SHARE
TWEET

Untitled

shniaga Feb 22nd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top