Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Map<Integer, List<String>> lengthMap = new HashMap<>();
for(String string : strings)
{
List<String> sameLength = null;
Integer length = string.length();
if(lengthMap.get(length) == null)
{
sameLength = new ArrayList<>();
sameLength.add(string);
lengthMap.put(length, sameLength);
}else
{
List<String> sameLengthString = lengthMap.get(length);
sameLengthString.add(string);
}
}
return lengthMap;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment