I have a list of User objects defined as follows:
public class User { private String userId;
List example:
List<User> users = Arrays.asList( new User("JOHNSMITH", "John", "Smith", "Some info", 1), new User("JOHNSMITH", "John", "Smith", "Updated info", 2), new User("JOHNSMITH", "John", "Smith", "Latest info", 3), new User("BOBDOE", "Bob", "Doe", "Personal info", 1), new User("BOBDOE", "Bob", "Doe", "Latest info", 2) );
I need a way to filter this list, so that I only get the latest version for each user, i.e.
{"JOHNSMITH", "John", "Smith", "Latest info", 3}, {"BOBDOE", "Bob", "Doe", "Latest info", 2}
What is the best way to achieve this using the Java8 Stream API?
java java-8 java-stream
Nick melis
source share