Advertisement
shniaga

Untitled

Feb 22nd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. package ListsExercise;
  2.  
  3. import java.util.*;
  4. import java.util.stream.Collectors;
  5.  
  6. public class AppendArrays {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. String inputLine = scanner.nextLine();
  11. List<String> inputLineList = Arrays.stream(inputLine.split("\\|+")).collect(Collectors.toList());
  12. Collections.reverse(inputLineList);
  13.  
  14. String finalLine = "";
  15.  
  16. for (int i = 0; i < inputLineList.size(); i++) {
  17. finalLine += inputLineList.get(i) + " ";
  18. }
  19. List<String> finalList = Arrays.stream(finalLine.split("\\s+")).collect(Collectors.toList());
  20.  
  21. while (finalList.contains("")) {
  22. int nullPosition = finalList.indexOf("");
  23. if (nullPosition != -1) {
  24. finalList.remove(nullPosition);
  25. } else {
  26. break;
  27. }
  28. }
  29. System.out.println(String.join(" ", finalList));
  30.  
  31.  
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement