Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Update class name
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class UniqueByPojoField {
private static class Domain {
Integer id;
String name;
public Integer getId() {
return id;
public String getName() {
return name;
static Domain create(Integer id, String name) {
Domain domain = new Domain(); = id; = name;
return domain;
public static void main(String[] args) {
//Просто генерация 1000 объектов
List<Domain> collection = IntStream.range(1, 1000)
.mapToObj(i -> Domain.create(i, "Name " + i))
final HashMap<Integer, Domain> collector = Maps.newHashMapWithExpectedSize(collection.size());
collection.forEach(domain -> collector.put(domain.getId(), domain));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment