배열
의 길이 출력.
public class gyujin {
public static void main(String[] args) {
int[] array = { 1, 2, 3 };
int length = array.length;
System.out.println(length);
}
}
/* 출력결과
5
*/
public class gyujin {
public static void main(String[] args) {
int[] array = new int[10];
int length = array.length;
System.out.println(length);
}
}
/* 출력결과
10
*/
배열의 크기를 10으로 초기화하였기때문에, 배열에 따로 원소를 넣지 않아도 10으로 출력된다.
문자열
의 길이 출력.
public class gyujin{
public static void main(String[] args){
String lengthTest2 = "lengthSizeTest";
System.out.println( lengthTest2.length() );
}
}
/* 출력결과
14
*/
컬렉션프레임워크 타입
의 길이 출력.
public class gyujin{
public static void main(String[] args){
ArrayList<Object> sizeTest = new ArrayList<Object>();
sizeTest.add(10);
sizeTest.add(20);
System.out.println( sizeTest .size() );
}
}
/* 출력결과
2
*/