title: Java all determine elements are same in a list
body: <p>I am trying to determine to see if all elements in a list are same.
  such as:</p>
  
  <pre><code>(10,10,10,10,10) --&gt; true
  (10,10,20,30,30) --&gt; false
  </code></pre>
  
  <p>I know hashset might be helpful, but i don't know how to write in java. </p>
  
  <p>this is the one I've tried, but didn't work:</p>
  
  <pre><code>public static boolean allElementsTheSame(List&lt;String&gt; templist) 
  {
  
      boolean flag = true;
      String first = templist.get(0);
  
      for (int i = 1; i&lt; templist.size() &amp;&amp; flag; i++)
      {
          if(templist.get(i) != first) flag = false;
      }
  
      return true;
  }
  </code></pre>