Created
May 5, 2017 06:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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