Skip to main content
added 218 characters in body
Source Link
David M
  • 73.2k
  • 13
  • 164
  • 187

The add method returns a boolean indicating whether or not the add succeeded. Might be clearer with indenting:

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

Or even better with braces:

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

The message is displayed if the add failed.

The add method returns a boolean indicating whether or not the add succeeded. Might be clearer with indenting:

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

The message is displayed if the add failed.

The add method returns a boolean indicating whether or not the add succeeded. Might be clearer with indenting:

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

Or even better with braces:

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

The message is displayed if the add failed.

Source Link
David M
  • 73.2k
  • 13
  • 164
  • 187

The add method returns a boolean indicating whether or not the add succeeded. Might be clearer with indenting:

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

The message is displayed if the add failed.