fork download
  1.  
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class MyBasicArrayList {
  8.  
  9. public static void main(String[] a){
  10.  
  11. ArrayList<String> al = new ArrayList<String>();
  12. //add elements to the ArrayList
  13. al.add("JAVA");
  14. al.add("C++");
  15. al.add("PERL");
  16. al.add("PHP");
  17. System.out.println(al);
  18. //get elements by index
  19. System.out.println("Element at index 1: "+al.get(1));
  20. System.out.println("Does list contains JAVA? "+al.contains("JAVA"));
  21. //add elements at a specific index
  22. al.add(2,"PLAY");
  23. System.out.println(al);
  24. System.out.println("Is arraylist empty? "+al.isEmpty());
  25. System.out.println("Index of PERL is "+al.indexOf("PERL"));
  26. System.out.println("Size of the arraylist is: "+al.size());
  27. }
  28. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
[JAVA, C++, PERL, PHP]
Element at index 1: C++
Does list contains JAVA? true
[JAVA, C++, PLAY, PERL, PHP]
Is arraylist empty? false
Index of PERL is 3
Size of the arraylist is: 5