1. length : 배열의 길이를 알고자 할 때 사용한다.
int[] arr = new int[100];
System.out.println(arr.length);
// 결과 : 100
2. length() : 문자열의 길이를 알고자 할 때 사용한다.
String hello = "HELLO";
System.out.println(test.length());
// 결과 : 5
3. size() : 컬렉션프레임워크(ArrayList, Set 등) 타입의 길이를 알고자 할 때 사용한다.
ArrayList<Object> hello = new ArrayList<Object>();
System.out.println(hello.size());
// 결과 : 0
'개념 창고 > JAVA' 카테고리의 다른 글
[JAVA] charAt() (0) | 2022.12.07 |
---|---|
[JAVA] 대소문자 변환 & 비교 (toUpperCase, toLowerCase, equalsIgnoreCase) (0) | 2022.12.07 |
인터페이스(interface) (0) | 2022.06.29 |
추상 클래스 (0) | 2022.06.28 |
상속을 사용하는 때 (0) | 2022.06.27 |