0

In the following piece of code

int[] arr =new int[] {1,2,5,1,1,1};
    List<Integer> arrList =new ArrayList(Arrays.asList(arr));
    Iterator<Integer> itr =arrList.iterator();
    while(itr.hasNext()) {
        Integer i =itr.next();     // classcast exception
    }

Not sure why it need to be casted again

Execption log is

Exception in thread "main" java.lang.ClassCastException: class [I cannot be cast to class java.lang.Integer ([I and java.lang.Integer are in module java.base of loader 'bootstrap')
at dsa/dsa.streamPractice.main(streamPractice.java:14)
abhishek
  • 149
  • 12

0 Answers0