import java.util.ArrayList;
import java.util.List;
public class ListReturn6 {
public static List getSubList(List<Integer> list) {
List<Integer> subList = new ArrayList<Integer>();
for (Integer a : list) {
if (a > 50) {
subList.add(a);
}
}
return subList;
}
public static void main(String[] args) {
List<Integer> intList = new ArrayList<Integer>();
intList.add(24);
intList.add(45);
intList.add(99);
intList.add(44);
intList.add(77);
intList.add(40);
intList.add(87);
List<Integer> subList = getSubList(intList);
System.out.println("Sub list is");
for (Integer a : subList) {
System.out.print(a + " ");
}
}
}
In Main method created a List named intList.
Added elements there and passed to method ListReturn6'method getSubList()
getSubList signature is
public static List getSubList(List<Integer> list)
By looking parameter you can see that this method is taking List of integers as argument
After procession this method is also returning list.
You can checkout https://ebhor.com/java-return-arrays/
int[]
is the name of a type, andArrayList<int>
is the name of a different type.