[Java] What is the difference between Array.size() vs Array.length?


In Arrays what is the difference between Array.size() and Array.length

1 Answer

3 years ago by

We use .length on an array, and .size() to find the length on Lists

import java.util.Arrays;

public class JavaArrays {
  public static void main(String[] args) {
	String[] colors = { "red", "green", "blue", "orange", "maroon", "blue" };

	int arrayLength = colors.length;
	int listLength = Arrays.asList(colors).size();
  }
}
3 years ago by Karthik Divi