「Java入門」HashSet要素をソートするコード

Javaコード
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.TreeSet;

public class HashSetSortingTest {
public static void main(String[] args) {
HashSet<String> names = new HashSet<String>();
names.add(“Akihabara”);
names.add(“Crteam”);
names.add(“Basarona”);
names.add(“Mondy”);
names.add(“Dina”);
System.out.println(“HashSet before sorting : \n” + names);
List<String> tempList = new ArrayList<String>(names);
Collections.sort(tempList);
System.out.println(“HashSet element in sorted order :\n ” + tempList);
TreeSet<String> sorted = new TreeSet<String>(names);
System.out.println(“HashSet sorted using TreeSet : \n” + sorted);

}

}

実行結果
HashSet before sorting :
[Mondy, Dina, Crteam, Basarona, Akihabara]
HashSet element in sorted order :
[Akihabara, Basarona, Crteam, Dina, Mondy]
HashSet sorted using TreeSet :
[Akihabara, Basarona, Crteam, Dina, Mondy]