누구나 사용자 입력을 인쇄하고 ArrayList를 같은 대화 상자에서 정렬 할 수 있습니까? (예 : User input = **Toyota, Mazda, Ford**
. Sorted input =**Ford, Mazda, Toyota**
).똑바로 입력을 표시하고 같은 대화 상자에서 ArrayList를 정렬하는 방법
대화 상자로 작업하는 것은 이번이 처음입니다. 사용할 수있는 추가 도구가 있습니까? 또는 Collections.sort(auto);
을 별도의 클래스로 작성한 다음 인쇄 할 때 삽입해야합니까? 여기
코드가 모습입니다 같은 :
Scanner in = new Scanner(System.in);
ArrayList<String> auto = new ArrayList<>();
boolean done = false;
do {
String autoList = JOptionPane.showInputDialog(null, "Enter an Auto you like (q to finish):",
"click OK for each auto entry");
if (autoList.equalsIgnoreCase("q")) {
break;
}
auto.add(autoList);
} while (!done);
Collections.sort(auto);
JOptionPane.showMessageDialog(null, "Arra list " + auto
+ "\n Sorted list is " + auto);
// should print straight user's input on one line and sorted Array list on the second line
in.close();
당신이 원래의 목록을 인쇄되지 않습니다하는 문제를 건가요? 원래 목록이 수정되었다고 JavaDoc에 명시되어 있기 때문에 이것이 문제가된다. 'JOptionPane.showMessageDialog (null, "Arra list"+ auto + "\ n 정렬리스트는"+ Collections.sort (auto) ");와 같이 정렬 할 수있다. –
예, 원본 목록이 인쇄되지 않았고 대화 상자가'Collections.sort (자동) '바로 뒤에 오르기 때문에 원본 목록이 인쇄되어 있다는 것을 알고 있습니다. 'Collections.sort (auto)'를 추가하려고 시도했지만 _ "연산자 +가 인수 유형 String, void"에 대해 정의되지 않았습니다. "+"연산자를 "+"로 변경하면 오류 메시지에 _ "JOptionPane 유형의 메서드 showMessageDialog (Component, Object)가 인수 (null, String, void)에 적용 할 수 없습니다"_ : – Rish