0
我試圖鏈接列表轉換爲Java數組如下面的代碼中鏈表數組中的Java
import java.io.*;
import java.util.*;
public class LinkedLst
{
public static void main(String[] args) throws IOException
{
FileInputStream fis = new FileInputStream("input");
LinkedList<Integer> ll = new <Integer>LinkedList();
int c;
while((c = fis.read())!=-1)
ll.add(new Integer(c));
Integer[] arr = ll.toArray(new Integer[ll.size()]);
System.out.println(arr);
fis.close();
}
}
與輸入文件如下
12
13
14
15
16
我能夠編譯但我最終在運行時出現以下錯誤
[Ljava.lang.Integer;@2098746b
有人能幫我解決這個問題嗎?
的錯誤是由於整數[] ARR = ll.toArray(新的整數[ll.size()]);代碼行 – Ashok 2014-10-10 10:17:49
是錯誤還是代碼工作並提供輸出?你不能打印這樣的數組。相反,遍歷它的索引並單獨打印它們。 – 2014-10-10 10:18:18
我搜索了其他線程,但他們的解釋並沒有糾正我的錯誤 – Ashok 2014-10-10 11:08:02