title: More efficient alternative to these "for" loops?
body: <p>I'm taking an introductory course to Java and one of my latest projects involve making sure an array doesn't contain any duplicate elements (has distinct elements). I used a for loop with an inner for loop, and it works, but I've heard that you should try to avoid using many iterations in a program (and other methods in my classes have a fair number of iterations as well). Is there any efficient alternative to this code? I'm not asking for code of course, just "concepts." Would there potentially be a recursive way to do this? Thanks!</p>
  
  <p>The array sizes are generally &lt;= 10.</p>
  
  <pre><code>/** Iterates through a String array ARRAY to see if each element in ARRAY is
   *  distinct. Returns false if ARRAY contains duplicates. */
  boolean distinctElements(String[] array) { //Efficient?
      for (int i = 0; i &lt; array.length; i += 1) {
          for (int j = i + 1; j &lt; array.length; j += 1) {
              if (array[i] == array[j]) {
                  return false;
              }
          }
      } return true;
  }
  </code></pre>