AlexKondov

Java Combine Lists

May 23rd, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class CombineListsOfLetters {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner in = new Scanner(System.in);
  9.         String firstInput = in.nextLine();
  10.         firstInput = firstInput.replaceAll(" ", "");
  11.         String secondInput = in.nextLine();
  12.         secondInput = secondInput.replaceAll(" ", "");
  13.        
  14.         ArrayList<Character> firstChars = new ArrayList<> ();
  15.         ArrayList<Character> secondChars = new ArrayList<> ();
  16.        
  17.         for (char c : firstInput.toCharArray()) {
  18.             firstChars.add(c);
  19.         }
  20.        
  21.         for (char c : secondInput.toCharArray()) {
  22.             secondChars.add(c);
  23.         }
  24.        
  25.         for (int i = 0; i < firstChars.size(); i++) {
  26.             System.out.print(firstChars.get(i) + " ");
  27.             if (secondChars.contains(firstChars.get(i))) {
  28.                 secondChars.remove(firstChars.get(i));
  29.             }
  30.         }
  31.         for (int i = 0; i < secondChars.size(); i++) {
  32.             System.out.print(secondChars.get(i) + " ");
  33.         }
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment