Advertisement
Masovski

[Java Basics][Collections-HW] 09. Combine Lists of Letters

May 24th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class CombineListsOfLetters {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.        
  9.         String firstLine = sc.nextLine();
  10.         String secondLine = sc.nextLine();
  11.        
  12.         String[] firstStrArr = firstLine.split(" ");
  13.         String[] secondStrArr = secondLine.split(" ");
  14.        
  15.         ArrayList<Character> l1 = new ArrayList<>();
  16.         ArrayList<Character> tempList = new ArrayList<>();
  17.         ArrayList<Character> l2 = new ArrayList<>();
  18.        
  19.         for (int i = 0; i < firstStrArr.length; i++) {
  20.             l1.add(i, firstStrArr[i].charAt(0));
  21.         }
  22.         tempList.addAll(l1);
  23.        
  24.         for (int i = 0; i < secondStrArr.length; i++) {
  25.             l2.add(i, secondStrArr[i].charAt(0));
  26.         }
  27.         for (int i = 0; i < l2.size(); i++) {
  28.             if(!(tempList.contains(l2.get(i)))) {
  29.                 l1.add(l2.get(i));
  30.             }
  31.         }
  32.         for (Character character : l1) {
  33.             System.out.print(character + " ");
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement