SHARE
TWEET

Append Arrays

LoraOrliGeo Apr 15th, 2019 157 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package feb20_Lists_Exercises;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6. import java.util.Scanner;
  7. import java.util.stream.Collectors;
  8.  
  9. public class P7_AppendArrays {
  10.     public static void main(String[] args) {
  11.         @SuppressWarnings("resource")
  12.  
  13.         Scanner sc = new Scanner(System.in);
  14.         List<String> input = Arrays.stream(sc.nextLine().split("\\|")).collect(Collectors.toList());
  15.  
  16.         List<String> output = new ArrayList<>();
  17.  
  18.         for (int i = input.size() - 1; i >= 0; i--) {
  19.             String[] numbers = input.get(i).split("\\s+");
  20.             for (int j = 0; j < numbers.length; j++) {
  21.                 if (!numbers[j].equals("")) {
  22.                     output.add(numbers[j]);
  23.                 }
  24.             }
  25.         }
  26.  
  27.         String print = output.toString().trim();
  28.         System.out.println(print.replaceAll("\\[|,|\\]", ""));
  29.     }
  30. }
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