lambda - Filter Java Stream to 1 and only 1 element -
i trying use java 8 stream s find elements in linkedlist . want guarantee, however, there 1 , 1 match filter criteria. take code: public static void main(string[] args) { linkedlist<user> users = new linkedlist<>(); users.add(new user(1, "user1")); users.add(new user(2, "user2")); users.add(new user(3, "user3")); user match = users.stream().filter((user) -> user.getid() == 1).findany().get(); system.out.println(match.tostring()); } static class user { @override public string tostring() { return id + " - " + username; } int id; string username; public user() { } public user(int id, string username) { this.id = id; this.username = username; } public void setusername(string username) { this.username = username; } public void setid(int id) { this.id = id; } public string getusername() { retur