October 2018
Intermediate to advanced
370 pages
9h 15m
English
Create a method in Java that returns an arrayList of integers:
public static ArrayList<Integer> getIntList(){ ArrayList<Integer> integers = new ArrayList<>(); integers.add(1);integers.add(2);integers.add(3); return integers;}
getIntList returns an array that contains three elements. Call this function in Kotlin to access the list and add more elements in it:
var list = CallJava.getIntList()//var list: ArrayList<Int> = CallJava.getIntList()list.add(4)for (element in list) { println("Element $element")}
CallJava.getIntList() returns ArrayList, which can be assigned to a list type of variables. We explicitly declare the type of the list by using the ArrayList<Int> name:
var list: ArrayList<Int> = CallJava.getIntList() ...Read now
Unlock full access