+ 3

How to run this code, does it exist in sololearn?

im getting "can not find symbol" errors for this peice of code, does it work in this app? if so how do i fix it ArrayList<Integer> sample = new ArrayList<Integer>(); sample.add("example");

18th Mar 2017, 7:24 AM
David Busev
David Busev - avatar
6 odpowiedzi
+ 13
Yes, it works at the playground. Make sure you imported it: import java.util.ArrayList;
18th Mar 2017, 7:49 AM
Tashi N
Tashi N - avatar
+ 10
@Vishal You're right!
18th Mar 2017, 7:52 AM
Tashi N
Tashi N - avatar
+ 9
@Vishal I think he didn't, because then it would result in a type error. But both answers combined will make the solution ^^
18th Mar 2017, 7:55 AM
Tashi N
Tashi N - avatar
+ 4
//You are adding ArrayList<Integer> with a String. //You need to change with the follows : import java.util.*; ArrayList<String> sample = new ArrayList<String>(); sample.add("example"); // this will work
18th Mar 2017, 7:51 AM
Vishal Prajapati
+ 2
@Tashi N. I am assuming that he is import the java.util.* library.
18th Mar 2017, 7:53 AM
Vishal Prajapati
+ 2
@Tashi N, looks you are right also. So I had updated the answer.
18th Mar 2017, 7:56 AM
Vishal Prajapati