arraylist kotlin code example

Example 1: arraylist kotlin

fun main(args: Array<String>){  
  
    val arrayList = ArrayList<String>()//Creating an empty arraylist  
    arrayList.add("Ajay")//Adding object in arraylist  
    arrayList.add("Vijay")  
    arrayList.add("Prakash")  
    arrayList.add("Rohan")  
    arrayList.add("Vijay")  
    println(".......print ArrayList.......")  
    for (i in arrayList) {  
        println(i)  
    }  
}

Example 2: arraylist kotlin

fun main(args: Array<String>){  
  
    val arrayList = ArrayList<String>()//Creating an empty arraylist  
    arrayList.add("Ajay")//Adding object in arraylist  
    arrayList.add("Vijay")  
    arrayList.add("Prakash")  
    arrayList.add("Rohan")  
    arrayList.add("Vijay")  
    println(".......print ArrayList.......")  
    for (i in arrayList) {  
        println(i)  
    }  
}

Tags:

Misc Example