Java String with all unique characters

Description

Java String with all unique characters



//package com.demo2s;
import java.util.HashSet;

public class Main {
    public static void main(String[] argv) throws Exception {
        String string = "demo2s.com";
        System.out.println(allCharactersUnique(string));
    }//from  w w w.j a v  a  2s  .  c  o m

    public static boolean allCharactersUnique(String string) {
        HashSet<Character> set = new HashSet<>();
        for (char c : string.toCharArray())
            set.add(c);
        return set.size() == string.length();
    }
}



PreviousNext

Related