Created
April 5, 2017 06:05
-
-
Save omerhakanbilici/26d718b3f6a660f6e9e87b02cf27ad8a to your computer and use it in GitHub Desktop.
finding common letters
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; | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
[l, w]