예를 들어, 내가 문장열 라일리스트 삽입하십시오 작업공간에서 '5'. '에서' 는 순서 및 읽어들이기가 삽입에서 라일리스트 포지셔닝합니다 유지됩니까?
, 추가 요소를 검색하는 동안 경우 순서가 바뀌지 않습니다.
아래 코드는 실행하십시오 확인할 수 있다.
public class ListExample {
public static void main(String[] args) {
List<String> myList = new ArrayList<String>();
myList.add("one");
myList.add("two");
myList.add("three");
myList.add("four");
myList.add("five");
System.out.println("Inserted in 'order': ");
printList(myList);
System.out.println("\n");
System.out.println("Inserted out of 'order': ");
// Clear the list
myList.clear();
myList.add("four");
myList.add("five");
myList.add("one");
myList.add("two");
myList.add("three");
printList(myList);
}
private static void printList(List<String> myList) {
for (String string : myList) {
System.out.println(string);
}
}
}
다음 출력을 생성합니다.
Inserted in 'order':
one
two
three
four
five
Inserted out of 'order':
four
five
one
two
three
자세한 내용은 문서를 참조하십시오. '목록 (Java 플랫폼 SE7)'
그래, 왜 항상 똑같다. 1 의 [문서용으로]
>. 이 목록의 끝까지 첨부됩니다 지정된 요소. 매개변수입니다: e >. 이 목록은 요소점 스크램블된 덧붙여집니다 되돌려줍니다: true (지정되는 >. 콜레스티온자이드 (자바드랑드로비치))
라일리스트 추가 () '의' 구축
public boolean More ...add(E e) {
ensureCapacity(size + 1); // Increments modCount!!
elementData[size++] = e;
return true;
}
예 이 그대로 남아 있습니다. 그러나 왜안돼요 쉽게 테스트 할 수 있지? 다음, 라일리스트 읽어들입니다 채워 만드는 요소!