Skip to main content
added 415 characters in body
Source Link
Tom
  • 45.4k
  • 30
  • 142
  • 171

As others have answered, add returns a boolean indicating whether a has been added to the set. Its equivalent to

Set<String> s = new HashSet<String>(); for(String a:args) { if (s.contains(a)){ System.out.println("Duplicate detected:"+a); } else{ s.add(a); } } 

From the javadoc for the Set interface.

contains boolean contains(Object o) 
 Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that (o==null ? e==null :o.equals(e)). 

As others have answered, add returns a boolean indicating whether a has been added to the set. Its equivalent to

Set<String> s = new HashSet<String>(); for(String a:args) { if (s.contains(a)){ System.out.println("Duplicate detected:"+a); } else{ s.add(a); } } 

As others have answered, add returns a boolean indicating whether a has been added to the set. Its equivalent to

Set<String> s = new HashSet<String>(); for(String a:args) { if (s.contains(a)){ System.out.println("Duplicate detected:"+a); } else{ s.add(a); } } 

From the javadoc for the Set interface.

contains boolean contains(Object o) 
 Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that (o==null ? e==null :o.equals(e)). 
Source Link
Tom
  • 45.4k
  • 30
  • 142
  • 171

As others have answered, add returns a boolean indicating whether a has been added to the set. Its equivalent to

Set<String> s = new HashSet<String>(); for(String a:args) { if (s.contains(a)){ System.out.println("Duplicate detected:"+a); } else{ s.add(a); } }