stoyanmkd

String to Char arrList // Combine Lists of Letters

Feb 5th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3. public class _09_Combine_Lists_of_Letters {
  4. public static void main(String[] args) {
  5. Scanner input = new Scanner(System.in);
  6. String[] firstLine = input.nextLine().split(" ");
  7. String[] secondLine = input.nextLine().split(" ");
  8. ArrayList<Character> l1 = new ArrayList<Character>();
  9. ArrayList<Character> l2 = new ArrayList<Character>();
  10. l1 = addCharacters(firstLine, l1);
  11. l2 = addCharacters(secondLine, l2);
  12. ArrayList<Character> result = new ArrayList<Character>(l1);
  13. result = addCharactersFroml2(l1, l2, result);
  14. printResult(result, l1);
  15. }
  16. private static void printResult(ArrayList<Character> result, ArrayList<Character> l1) {
  17. for (Character character : result) {
  18. System.out.print(character + " ");
  19. }
  20. }
  21. private static ArrayList<Character> addCharactersFroml2(ArrayList<Character> l1,
  22. ArrayList<Character> l2, ArrayList<Character> result) {
  23. for (Character character : l2) {
  24. if (!l1.contains(character)) {
  25. result.add(character);
  26. }
  27. }
  28. return result;
  29. }
  30. private static ArrayList<Character> addCharacters(String[] line, ArrayList<Character> list) {
  31. for (String character : line) {
  32. list.add(character.charAt(0));
  33. }
  34. return list;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment