Skip to content

Instantly share code, notes, and snippets.

@omerhakanbilici
Created April 5, 2017 06:05
Show Gist options
  • Save omerhakanbilici/26d718b3f6a660f6e9e87b02cf27ad8a to your computer and use it in GitHub Desktop.
Save omerhakanbilici/26d718b3f6a660f6e9e87b02cf27ad8a to your computer and use it in GitHub Desktop.
finding common letters
import java.util.ArrayList;
import java.util.List;
public class Workouts999 {
/**
* common letters
*/
public static void main(String[] args) {
String word1 = "always";
String word2 = "following";
System.out.println(findCommonLetters(word1.toCharArray(), word2.toCharArray()));
}
private static List<Character> findCommonLetters(char[] array1, char[] array2) {
List<Character> characterList = new ArrayList<Character>();
for (char element1 : array1) {
for (char element2 : array2) {
if (element1 == element2 && !characterList.contains(element1)) {
characterList.add(element2);
}
}
}
return characterList;
}
}
@omerhakanbilici
Copy link
Author

Output:
[l, w]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment