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