我在显示已排序的数组时遇到问题。我有一个名单列表,我使用不同的排序算法排序。当我使用自己创建的字符串数组时,它会被排序。但是如果我尝试对从文件导入的数组进行排序,它会以二进制形式给出名称。
//Read the names into an Array
BufferedReader br = new BufferedReader(new FileReader(fileName));
List<String> list = new ArrayList<String>();
while ((names = br.readLine()) !=null)
{
list.add(names);
}
br.close();
String[] name= list.toArray(new String[0]);
BufferedReader user = new BufferedReader(new InputStreamReader(System.in));
//Sort the array first
//When i write this, it does not sort it, it just gives me names //with no space
InsertionSort.insertionSort(name);
System.out.println("\n Sorted Order:");
for(String n : name)
JOptionPane.showMessageDialog(null, n);
//Ask the user for name to search
JOptionPane.showInputDialog(null, "Enter a name to search for: ");
String Name= user.readLine();
user.close();