fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String[] ar = {"chicken", "goat", "cow", "camel", "elephant"};
  13. List<String> l = new LinkedList<>();
  14. for(String a : ar) {
  15. l.add(a);
  16. }
  17. List<String> l2 = new LinkedList<>();
  18. l2.add("one");
  19. l2.add("two");
  20. l.addAll(l2);
  21. reverse(l);
  22. remove(l);
  23. print(l);
  24. }
  25. public static void reverse(List<String> c) {
  26. ListIterator<String> it = c.listIterator(c.size());
  27. while(it.hasPrevious()) {
  28. System.out.printf("%s ", it.previous());
  29. }
  30. System.out.println();
  31. }
  32. static void remove(List<String> l) {
  33. l.subList(2, 4).clear();
  34. }
  35. public static void print(List<String> c) {
  36. for(String s: c) {
  37. System.out.printf("%s ", s);
  38. }
  39. }
  40. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
two one elephant camel cow goat chicken 
chicken goat elephant one two