'length'에 해당하는 글 1건

Java 의 Length

언어/Java 2008. 6. 16. 09:36

ㅎㅎ 역시 Java에서 배열의 Length는 Field Variable이였다. Method는 아니였다.
내 생각이지만 해당 배열의 element를 총괄하는 기능에서 사용되는 length 인것같다.
Object를 상속받아서 length() Method를 사용할 수 없다는 것인가?
==========================================================================
length는 배열의 field variable 입니다.

Ex)
String[] st = new String[3];

st[0] = "abc";
st[1] = "gogo";
st[2] = "good";

for(int x = 0; x < st.length; x++)
{
      System.out.println(st[x]);
}

st.length 라고 했을 때 3이 나온것은  abc의 길이가 3이라는 것이 아니고 st배열 속에 가지고 있는


element의 갯수가 3이라는 것입니다. 또한, String의 length()는 method지만, 배열타입의 length는 field

변수입니다. 배열속에 element가 더 생기거나 줄어들면 자동으로 length변수의 값이 바뀝니다.

영문자료

The members of an array type are all of the following;
The public final field length, which contains the number of components of the array(length may be positive of zero)

The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions All the members inherited from class Object; the only method of Object that is not inherited is its clone method

배열타입에 선언된 멤버는 public final인 length 변수와 public인 clone()메소드 뿐입니다.

자바 Language에서 기본적으로 사용되는 내용은 Java Language Specification을 보셔야 하니다.

http://java.sun.com/j2ee/1.4.2/docs/index.html 에서 API Document 바로 밑에 있습니다.

참고로 st는 Array Class가 아니고 Array Type입니다. 그래서 API Document에는 안나온것 입니다.

출처 : http://blog.naver.com/cyp57?Redirect=Log&logNo=32540845


WRITTEN BY
정현석
이것저것 끄적끄적....

,