Skip to content

Instantly share code, notes, and snippets.

@lon-io
Created May 5, 2017 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lon-io/5cdf867217f67574964ef55b38fe8af5 to your computer and use it in GitHub Desktop.
Save lon-io/5cdf867217f67574964ef55b38fe8af5 to your computer and use it in GitHub Desktop.
Java class with a fucntion to determine the number of unique strings in an array of strings
public class Unique{
public static void main(String [] args){
Unique unique = new Unique();
String[] _args = {"as", "as", "se", "so","so","an","no"};
System.out.println(unique.det(_args));
}
public int det(String [] args_){
int dup = 0;
System.out.println(args_.length);
for(int i = 0; i < args_.length; i++){
for(int j = 0; j < args_.length; j++){
if(i != j){
if(args_[i].equals(args_[j])){
dup +=1;
}
}
}
}
return args_.length - (dup);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment