In java, is there anyway to go from a array of objects that got returned to the number of objects in the array? [closed]

You need to use method size() to get the number of objects in a list:

List<String> list = new ArrayList<String>();
list.add("balh");
list.add("balh");
list.add("balh");
System.out.println(list.size());

OUTPUT:

3

and for array of objects, you need to use the final field length:

String[] array = {"blah", "blah", "blah"};
System.out.println(array.length);

OUTPUT:

3

Leave a Comment