int[] anArray;
anArray = new int[10];
anArray[0] = 100;
anArray[1] = 200;
anArray[2] = 300;
anArray[3] = 400;
anArray[4] = 500;
anArray[5] = 600;
anArray[6] = 700;
anArray[7] = 800;
anArray[8] = 900;
anArray[9] = 1000;
int[] anArray = {
100, 200, 300,
400, 500, 600,
700, 800, 900, 1000
};
the rows are allowed to vary in length
String[][] names = {
{"Mr. ", "Mrs. ", "Ms. "},
{"Smith", "Jones"}
};
length property is built-in.
System.out.println(anArray.length);
System.arraycopy()
public static void arraycopy(Object src, int srcPos,
Object dest, int destPos, int length)
class ArrayCopyDemo {
public static void main(String[] args) {
char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e',
'i', 'n', 'a', 't', 'e', 'd' };
char[] copyTo = new char[7];
System.arraycopy(copyFrom, 2, copyTo, 0, 7);
System.out.println(new String(copyTo));
}
}
array can be converted to String easily.
new String(copyTo)
java.util.Arrays.copyOfRange
class ArrayCopyOfDemo {
public static void main(String[] args) {
char[] copyFrom = {'d', 'e', 'c', 'a', 'f', 'f', 'e',
'i', 'n', 'a', 't', 'e', 'd'};
char[] copyTo = java.util.Arrays.copyOfRange(copyFrom, 2, 9);
System.out.println(new String(copyTo));
}
}
java.util.Arrays
binarySearch()
equals()
fill()
sort()
parallelSort()
댓글 없음:
댓글 쓰기