Browsing category:

Programming

Kotlin ArrayList and Loops Example

Kotlin ArrayList Kotlin ArrayList is also very similar to Java Arraylist. ArrayList<T> is the resizable-array implementation of the List interface. The ArrayList class has only a few methods in addition to the methods available in the List interface. val myArrayList = arrayListOf(“John”, “Fred”, “McKinsey”, “Morgan”, “Sarah”) //an arraylist of my friends val newFriendList = arrayListOf(“Musa”, “Victor”, “Timothy”) myArrayList.add(0, […]

OOP: What is an Interface?

An interface is a collection of abstract methods. It is a reference type in Java/Kotlin. It is similar to class. A class implements an interface, thereby inheriting the abstract methods of the interface. [tabs type=”horizontal”] [tabs_head] [tab_title] Java Code [/tab_title] [tab_title] Kotlin Code [/tab_title] [/tabs_head] [tab] public class HelloWorld { class Example implements InterfaceExample{ @Override public […]

Kotlin: Array vs List – Similarities and Differences

// Initializing array and list val array = arrayOf(1, 2, 3) val list = listOf(“apple”, “ball”, “cow”) val mixedArray = arrayOf(true, 2.5, 1, 1.3f, 12000L, ‘a’) // mixed Array val mixedList = listOf(false, 3.5, 2, 1.4f, 13000L, ‘b’) // mixed List Arrays An array is a container object that holds a fixed number of values […]

Kotlin Conditional Statements

If Statements Sometimes we may want to run our code only when a condition holds true. For example, let’s hypothetically assume that we run a bar and we only want to admit users who are 18 years old and above. in the code below we’re trying to access our code with a preset age of 16,  […]