gulzaar

Unique Character

Jan 8th, 2015
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. public class que1_array_unique {
  2.     public static boolean isUnique(String str) {
  3.         boolean[] char_set = new boolean[256];
  4.         for (int i = 0; i < str.length(); i++) {
  5.             int val = str.charAt(i);
  6.             if (char_set[val]) return false;
  7.             char_set[val] = true;
  8.         }
  9.         return true;
  10.     }
  11.  
  12.     public static void main(String[] args) {
  13.        
  14.         String[] words = {"abcde", "hello", "apple", "kite", "padle"};
  15.        
  16.         System.out.println("It will print true for Unique Characters\n");
  17.         for (String word : words) {
  18.             System.out.println(word + ": " + isUnique(word)+"\n");
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment