为什么类型转换在这里不起作用

Paw*_*wan -2 java

为什么类型转换在这种情况下不起作用?

int b[] = {1,2,3,4,5};
    ArrayList list = new ArrayList();
    for (int i = 0; i < b.length; i++) {
    list.add(i);
    }
        Collections.sort(list);
    int c = (int) list.get(0); // This line is giving error 
Run Code Online (Sandbox Code Playgroud)

如何解决这个错误?

nan*_*nda 10

第2行,而不是

ArrayList list = new ArrayList();
Run Code Online (Sandbox Code Playgroud)

尝试:

ArrayList<Integer> list = new ArrayList<Integer>();
Run Code Online (Sandbox Code Playgroud)

而是:

int c = (int) list.get(0);
Run Code Online (Sandbox Code Playgroud)

做就是了:

int c = list.get(0); 
Run Code Online (Sandbox Code Playgroud)