다음 방법 중 하나가 성능 적중에서 안전하지 않은 경우 List 크기가 클 것으로 가정합니다 (1,000 개의 개체가있을 수 있음).toArray (new MyObject [size]) 목록 반복 및 배열 채우기
I)
List<String> myList = new ArrayList<String>();
for(int i=0; i <=10; i++){
myList.add(""+i);
}
String[] array = myList.toArray(new String[myList.size()]);
myArrayMethod(array); // this method returns the array - it modifies the content but not size of array.
myListMethod(myList); // this method processes the list.
II)
List<String> myList = new ArrayList<String>();
for(int i=0; i <=10; i++){
myList.add(""+i);
}
String[] array = new String[myList.size()];
int i = 0;
for(String str : myList){
array[i] = myList.get(i);
i++;
}
myArrayMethod(array); // this method returns the array - it modifies the content but not size of array.
myListMethod(myList); // this method processes the list.
1,000 항목 크다? 오. – corsiKa
ii30)에서 예를 들어 – smas
@smas에서 foreach를 normal로 바꾸십시오. – dantuch