Я прошу пользователя ввести число в значения int checkId и checkUserId, а затем сравните их. Если он совпадает, следует распечатать заголовок.
Код: Выделить всё
Iterator < Post > iter = posts.iterator();
while (iter.hasNext()) {
if (Objects.equals(iter.next().getUserId(), checkUserId)) {
System.out.println("found UserId");
if (Objects.equals(iter.next().getId(), checkId)) {
System.out.println("found Id");
//prints the title of object
}
}
}
Код: Выделить всё
List result = posts.stream()
.filter(title -> checkId.equals(getId()))
.findAny()
.orElse(null);
Подробнее здесь: https://stackoverflow.com/questions/686 ... of-objects