0
how to fix it?
i am trting to convert an array into an ArrayList and check if a certain number is in the arrayList. the code isnt working as it supposed to be, it prints out Gibberish and not the actual numbers. i tried using toString, parseInt and all of that and it still not working. code: import java.util.*; public class Main { public static void main(String[] args) { int[] find7 = {3 , 5 , 6 , 7 , 3}; List arrL = Arrays.asList(find7); System.out.println(arrL); String contains7 = arrL.contains(7) ? "Boom!" : ""; System.out.println(contains7); } }
6 Respostas
+ 3
Integer[] find7 = {3 , 5 , 6 , 7 , 3};
List<Integer>arrL = Arrays.asList(find7);
I no nothing about Java ,but there is discussion on stackoverflow i came across ,I cudn't understand anything much but hopefully it helps you somehow
https://stackoverflow.com/questions/1467913/arrays-aslist-not-working-as-it-should
+ 3
Abhay yahel
This will not work. asList() does not convert primitives into their wrapper classes (autoboxing).
Short: asList() works only for objects.
This article gives some examples what you can do with primitives:
https://stackoverflow.com/questions/1073919/how-to-convert-int-into-listinteger-in-java
+ 1
Denise Roßberg ok, thanks!
0
yahel, Please post your code on code playground and share it in your question.
see this:
https://www.sololearn.com/post/75089/?ref=app
0
https://code.sololearn.com/c5L7T68uxj6P