Size:
For Collections (eg: Map, List, etc ): usually it use collection.size(),
eg
Map<Character, Integer> map = new HashMap<>();
int s1 = map.size();
List<Integer> list = Arrays.asList(a);
int s2 = list.size();
But For Array, it uses length,
eg
Integer[] array = new Integer[10];
int s3 = array.length;
For String, it uses length(),
String str = "string";
int s4 = str.length();
No comments:
Post a Comment