Created
June 3, 2013 11:33
-
-
Save keithmorris/5697576 to your computer and use it in GitHub Desktop.
Compare two char[] arrays for characters they do not have in common.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class Main { | |
public static void main(String[] args) { | |
char[] arrayA = {'a', 'e', 'i', 'o'}; | |
char[] arrayB = {'i', 'o', 'u', 'y'}; | |
ArrayList<Character> aList = new ArrayList<Character>(); | |
ArrayList<Character> bList = new ArrayList<Character>(); | |
ArrayList<Character> differences = new ArrayList<Character>(); | |
for (char item : arrayA) { | |
aList.add(item); | |
} | |
for (char item : arrayB) { | |
bList.add(item); | |
} | |
for (char item : arrayA) { | |
if (!bList.contains(item)) { | |
differences.add(item); | |
} | |
} | |
for (char item : arrayB) { | |
if (!aList.contains(item)) { | |
differences.add(item); | |
} | |
} | |
System.out.println(differences); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment