I have some list of words List<String> strings I have to make a word out of most frequent letters on each position.
For example for strings = {"qwerty", "qwer" , "ab", "bab"} the result would be "qwer"
Letters that appear once do not count
I came up to idea of creating a list
List<Map<String, Integer>> list;
Its size is equal to the string in strings of maximal size and the map would count number of characters on the position
IntStream.range(0, strings.stream().max(String::compareTo).get().length())
.forEachOrdered(i -> {
strings.stream().forEach(s -> {
if (s.length()>i){
Map<String,Integer> temp = list.get(i);
String character = s.charAt(i) + "";
Integer value = temp.get(character) == null ? 0 : temp.get(character) + 1;
temp.put(character, value);
list.add(i, temp);
}
});
});
Have no idea why id doesn't work
stringsis an array.