Advertisement
TzvetanIG

CombineListsOfLetters

May 23rd, 2014
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.awt.List;
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4.  
  5.  
  6.  
  7. public class _09_CombineListsOfLetters {
  8.  
  9.     public static void main(String[] args) {
  10.        
  11.         ArrayList<Character> list1 = readListChar();
  12.         ArrayList<Character> list2 = readListChar();
  13.        
  14.         list2.removeAll(list1);
  15.        
  16.         list1.addAll(list2);
  17.        
  18.         for (Character character : list1) {
  19.             System.out.print(character + " ");
  20.         }
  21.     }
  22.  
  23.  
  24.     public static ArrayList<Character> readListChar() {
  25.        
  26.         Scanner input = new Scanner(System.in);
  27.  
  28.         String[] chars = input.nextLine().split(" ");
  29.  
  30.         ArrayList<Character> list = new ArrayList<>();
  31.        
  32.         for (String ch : chars) {
  33.             list.add(ch.charAt(0));
  34.         }
  35.  
  36.         return list;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement