public static String computeUniqueName(String[] existingNames,String baseName){
  Set<String> nameSet=new HashSet<String>(Arrays.asList(existingNames));
  String proposedName=baseName;
  int i=2;
  while (nameSet.contains(proposedName)) {
    proposedName=baseName + i++;
  }
  return proposedName;
}

public static String computeUniqueName ( String [ ] existingNames , String baseName ) { Set < String > nameSet = new HashSet < String > ( Arrays . asList ( existingNames ) ) ; String proposedName = baseName ; int i = 2 ; while ( nameSet . contains ( proposedName ) ) { proposedName = baseName + i ++ ; } return proposedName ; }
returns a name guaranteed not to be equal to any of provided existing names . this is done by adding an integer suffix to the base name ( which itself should not contain any such suffix ) . for example , if the base name is foo , and the names bar and foo2 are already taken ( indicated via the existingnames parameter ) , then this method would return foo3 .
