I'm trying to figure out if there is an elegant way of doing the following using Java streams:
- take a list of Pojos where one of the fields is a String (eg surname)
- take a String that you want to search for (eg surnameTypedIn)
- find the Pojo in the list with the smallest Levenshtein distance (I'm using the Apache Commons StringUtils.getLevenshteinDistance)
- return the whole Pojo, not just the surname or the distance
So far the only way I've been able to do it is to create an intermediate map at each level, which works but feels very dirty. Is there an accepted way to do this, eg by implementing a custom Collector or something like that?