우리 모두가 Java에서 알고있는 것처럼, 다음 예제와 같이 해당 객체에 대한 참조가있는 'everyone'객체도 변경됩니다.List <>가 변경되면 LIst <>에 대한 다른 모든 참조가 변경됩니까?
List<String> mainList = new ArrayList<String>();
mainList.add("a");
mainList.add("c");
mainList.add("b");
mainList.add("d");
System.out.println(Arrays.toString(mainList.toArray(new String[mainList.size()]))); // randomly ordered strings [a, c, b, d]
List<String> referencedList = mainList;// referencedList contains the same unordered strings [a, c, b, d]
Collections.sort(mainList);// mainList is sorted [a, b, c, d]
System.out.println(Arrays.toString(referencedList.toArray(new String[ referencedList.size()]))); // the referenced list is also sorted
배열하지만, 참조 된 배열의 모든 걸쳐 업데이트됩니다 내에서만 객체가 정렬되지 않은 유지하는 목록 <>을 얻을 수있는 방법이 있습니까?
'List-> toArray-> toString' 콤보를 사용할 필요가 없습니다. '[element1, element2, ..., elementN]'형식으로 내용을 인쇄하려면'List' 자체에서'toString'을 사용하십시오. 따라서 System.out.println (Arrays.toString (mainList.toArray (new String [mainList.size()]));) 대신'System.out.println (mainList); – Pshemo