fork 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. List<String> list = Arrays.asList(("zero\n"
  13. + "test0\n"
  14. + "one\n"
  15. + "test1\n"
  16. + "two\n"
  17. + "test2").split("\n"));
  18. LinkedHashMap<String, String> linked = new LinkedHashMap<>();
  19. for (int i = 0; i < list.size(); i += 2) {
  20. linked.put(list.get(i), list.get(i + 1));
  21. }
  22.  
  23. linked.forEach((k, v) -> System.out.println(k + ":" + v));
  24. }
  25. }
Success #stdin #stdout 0.13s 2184192KB
stdin
Standard input is empty
stdout
zero:test0
one:test1
two:test2