+ 2
Help me, my code is not producing any output.
Is this some kind of bug in sololearn? The Java compiler is not producing any output. It often does this, but if I do an edit to the code, it works. Not for this code, it's not working :( Anyone know what's going on? https://code.sololearn.com/cg3sYJShwC63/?ref=app
6 Respuestas
+ 4
End the comment with */.
+ 2
recommend use List<String> al = new ArrayList<>(); instead of
ArrayList al = new ArrayList();
else sololearn will through an error
Note: ./Playground/ArrayListDemo.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
+ 1
import java.util.*;
public class ArrayListDemo {
public static void main(String args[]) {
List<String> al = new ArrayList<>();
System.out.println("Initial size of al: "+ al.size()/2);
al.add("C");
al.add("A");
al.add("E");
al.add("B");
al.add("D");
al.add("F");
al.add(1, "A2");
//al.addAll(al);
System.out.println("Size of al after additions: " + al.size());
System.out.println("Contents of al: " + al);
al.remove("F");
al.remove(2);
System.out.println("Size of al after additions: " + al.size());
System.out.println("Contents of al: " + al);
// al.clear();
}
}
+ 1
- store different types is possible with this trick, but I'm not recommended it because it is confused
ArrayList<Object> arr = new ArrayList<>();
arr.add("String");
arr.add(20);
arr.add(true);
- sometimes SoloLearn returns 'no output' instead there is some stupid error like } missing, yes it is bug
0
CarrieForle ooh wow I feel dumb :-/
I have another clarification to be made. I'm able to add elements of different data types to my ArrayList. How is that working?
0
HrCoder
I'm able to add data of different data types in my ArrayList, what about that? Is it usable like that or, it's not safe or something?