title: When to initialize an array with 256
body: <p>I was looking through the cracking the coding interview book solutions and noticed the following problem: </p>
  
  <p>Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?</p>
  
  <p>This was one of the solutions provided: </p>
  
  <pre><code>public static boolean isUniqueChars2(String str) {
    boolean[] char_set = new boolean[256];
      for (int i = 0; i &lt; str.length(); i++) {
        int val = str.charAt(i);
        if (char_set[val]) return false;
        char_set[val] = true;
      }
     return true;
   }
  </code></pre>
  
  <p>Why is the <code>char_set</code> array initialized with a size of 256? I was thinking that it was because there are 128 ascii characters but I'm not sure. Also, this solution seems to be in Java, but would an initial size also be necessary if this was done in C++?</p>