Skip to content

Instantly share code, notes, and snippets.

@keithmorris
Created June 3, 2013 11:33
Show Gist options
  • Save keithmorris/5697576 to your computer and use it in GitHub Desktop.
Save keithmorris/5697576 to your computer and use it in GitHub Desktop.
Compare two char[] arrays for characters they do not have in common.
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