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); } }

31st Jul 2020, 10:38 AM
Yahel
Yahel - avatar
5 odpowiedzi
+ 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
31st Jul 2020, 11:12 AM
Abhay
Abhay - avatar
+ 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
31st Jul 2020, 1:20 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Denise Roßberg ok, thanks!
31st Jul 2020, 1:34 PM
Yahel
Yahel - avatar
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
31st Jul 2020, 10:51 AM
The future is now thanks to science
The future is now thanks to science - avatar
0
https://code.sololearn.com/c5L7T68uxj6P
31st Jul 2020, 10:55 AM
Yahel
Yahel - avatar