|7ÀÏÂ÷|
¹è¿°ú ÂüÁ¶º¯¼ö
ÀÚ¹Ù¿¡¼ÀÇ ¹è¿Àº ¶ÇÇÑ
°´Ã¼ÀÌ´Ù. ¹è¿ÀÇ ¸â¹öÀÎ length ³»¿¡´Â ¹è¿ÀÇ ±æÀÌ°¡ µé¾îÀÖ´Ù.
class M {
public static
void main(String[] arg) {
String[] s =
{"ù°","µÑ°","¼Â°"};
System.out.println(s.length);
}
}
D:\JavaAI>java
M
3
============================================
¹è¿¿¡¼ÀÇ index´Â 0
ºÎÅÍ ½ÃÀÛÇÑ´Ù.
class M {
public static void main(String[] arg)
{
String[] s =
{"ù°","µÑ°","¼Â°"};
System.out.println(s[1]);
}
}
D:\JavaAI>java
M
µÑ°
==============================================
class M
{
public static void main(String[] arg)
{
String[] s =
{"ù°","µÑ°","¼Â°"};
String[] ss =
s;
System.out.println(ss[0]);
System.out.println(ss.length);
}
}
D:\JavaAI>java
M
ù°
3
class M {
public static void main(String[] arg)
{
String[] s =
{"ù°","µÑ°","¼Â°"};
String[] ss =
s;
ss[0] = "»õ·Î¿î
ù°";
System.out.println(s[0]);
System.out.println(ss[0]);
}
}
D:\JavaAI>java
M
»õ·Î¿î ù°
»õ·Î¿î ù°
½ÇÁ¦ instance¸¦ °¡¸®Å°°í ÀÖ´Â ÂüÁ¶º¯¼ö s¸¦ ÂüÁ¶º¯¼ö ss¿¡ ´ëÀÔÇϸé
instance¹è¿ÀÌ ±×´ë·Î
º¹»çµÈ´Ù. ±×·¯³ª ss[0]À» ¹Ù²Ù¸é ¸í½ÃÀûÀ¸·Î s[0]À» ¹Ù²ÙÁö ¾Ê´õ¶óµµ °ªÀÌ ¹Ù²î¾î Áö°Ô µÈ´Ù.
s
¿Í ss ´Â ¸Þ¸ð¸®»óÀÇ instance°¡ ¾Æ´Ï¶ó ¸Þ¸ð¸®»óÀÇ instance¸¦ °¡¸®Å°´Â ÁÖ¼Ò¸¦ °¡Áø ÂüÁ¶º¯¼ö
À̱⠶§¹®ÀÌ´Ù. ÀÚ¹Ù¸¦ ÀÌÇØ
Çϴµ¥ ÀÖ¾î¼ ¾ÆÁÖ Áß¿äÇÑ °³³äÀÌ µÈ´Ù.
´ÙÀ½¿¡´Â MethodÀμö¿Í ÂüÁ¶º¯¼ö¿¡ ´ëÇÑ ³»¿ëÀÌ ¿Ã¶ó¿Ã
¿¹Á¤ÀÔ´Ï´Ù.