borovaneca

AppendArrays

Feb 12th, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. package Fundamentals.List.Exercise.MoreExercise;
  2.  
  3. import java.util.*;
  4.  
  5. public class AppendArrays {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String[] input = scanner.nextLine().split("\\|");
  10.  
  11.         List<String> outputList = new ArrayList<>();
  12.  
  13.         for (int i = 0; i < input.length; i++) {
  14.             String[] currentArray = input[i].split("[\\s+]");
  15.  
  16.             for (int j = currentArray.length - 1; j >= 0; j--) {
  17.                 if (!currentArray[j].equals("")) {
  18.                     outputList.add(0, currentArray[j]);
  19.                 }
  20.             }
  21.         }
  22.         outputList.forEach(e -> System.out.print(e + " "));
  23.     }
  24. }
  25. //        List<String> input = Arrays.stream(scanner.nextLine().split("\\|")).collect(Collectors.toList());
  26. //        for (int i = 0; i < input.size(); i++) {
  27. //            String currentItem = input.get(i);
  28. //            if (currentItem.contains(" ")) {
  29. //                currentItem = currentItem.replaceAll("\\s+", "");
  30. //            }
  31. //            for (int j = currentItem.length() - 1; j >= 0; j--) {
  32. //                outputList.add(0, String.valueOf(currentItem.charAt(j)));
  33. //            }
  34. //        }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment