Java examples for Algorithm:String
is String having Unique Character Using Loop
public class Main { public static boolean isUnique(String str){ // Time: O(n^2), Space: take extra space to sort for(int i=0; i<str.length(); i++){ for(int j=i+1; j<str.length(); j++){ if(str.charAt(i)==str.charAt(j)) return false; }//from w w w .j a v a2s . com } return true; } // Test public static void main(String[] args){ String str="Hello"; System.out.print(isUnique(str)+" "); String str_2=""; System.out.print(isUnique(str_2)+" "); String str_3="He"; System.out.print(isUnique(str_3)+" "); String str_4=" "; System.out.print(isUnique(str_4)+" "); } }