Skip to main content
List<Item> result = new ArrayList<Item>(); Set<String> titles = new HashSet<String>(); for( Item item : originalList ) { if( titles.add( item.getTitle() ) { result.add( item ); } } 

add() of the Set returns false if the element already exists.

List<Item> result = new ArrayList<Item>(); Set<String> titles = new HashSet<String>(); for( Item item : originalList ) { if( titles.add( item.getTitle() ) { result.add( item ); } } 

add() of the Set returns false if the element already exists.

List<Item> result = new ArrayList<Item>(); Set<String> titles = new HashSet<String>(); for(Item item : originalList) { if(titles.add(item.getTitle()) { result.add(item); } } 

add() of the Set returns false if the element already exists.

Source Link
Aaron Digulla
  • 330.1k
  • 111
  • 626
  • 840

List<Item> result = new ArrayList<Item>(); Set<String> titles = new HashSet<String>(); for( Item item : originalList ) { if( titles.add( item.getTitle() ) { result.add( item ); } } 

add() of the Set returns false if the element already exists.