HW1/src/com/company/Main.java
//Question2: Write a program to check if a string has all unique characters.
Write a program to check if a string has all unique characters.
Write a program to check if a string has all unique characters .
public static boolean ifAllUnique(String s) {
        if (s == null || s.length() == 0) return true;
        Map<Character, Integer> map = new HashMap<>();
        for (char c : s.toCharArray()) {
            if (map.containsKey(c)) {
                return false;
            } else {
                map.put(c, 1);
            }
        }
        return true;
    }
public static boolean ifAllUnique ( String s ) { if ( s == null || s . length ( ) == 0 ) return true ; Map < Character , Integer > map = new HashMap < > ( ) ; for ( char c : s . toCharArray ( ) ) { if ( map . containsKey ( c ) ) { return false ; } else { map . put ( c , 1 ) ; } } return true ; }
Question2: Write a program to check if a string has all unique characters.
Question2 : Write a program to check if a string has all unique characters .