+ 1

Java code(convert array to arraylist)

from the code,i found that convert string Array to ArrayList would success,but convert int Array to ArrayList will fail. did only string work? if not, why? or this is fixed? https://code.sololearn.com/cc5wFZXngU74

8th Jun 2019, 2:17 PM
Tzion
Tzion - avatar
4 ответов
+ 1
https://code.sololearn.com/cabVEhXWvPi0/?ref=app I'm pretty sure it worked. When you declared your integer array, you forgot all of the letters. You had: nt[] arr1 = {...}; You needed: Integer[] arr1 = {...};
8th Jun 2019, 2:31 PM
Zeke Williams
Zeke Williams - avatar
+ 1
Well of course Rael . It isn't just needed for the arraylist; you need to use the correct keywords to declare EVERYTHING in statically typed languages like Java and C++ for the entire program to work. 'nt' isn't a Java keyword, so your program was failing there. It wasn't failing at the arraylist because the program never got there
8th Jun 2019, 2:39 PM
Zeke Williams
Zeke Williams - avatar
+ 1
ArrayList implements List and it inherited Collection. Collection is group of objects. int is not Object, String and Integer are objects so they are correct types
8th Jun 2019, 7:59 PM
zemiak
0
Zeke Williams oh it need full integer word ,instead of arraylist, any other need full name of data type? linkedlist?
8th Jun 2019, 2:35 PM
Tzion
Tzion - avatar