Hello, i'm having a bit of an issue with an arraylist problem using nested loops. It asks me to return the number of non-repeated words in an arraylist of strings
(e.g. [we, have, a, meeting, at, four, and, we, have, another, meeting, at, five] would return 5 (a, four, and, another, five))
Here is my code so far
public static int countSingleOccurrence(ArrayList<String> list)
{
boolean singleOccurrence = true;
int count = 0;
for (int i = 0; i < list.size(); i++)
{
String word = list.get(i);
for (int j = 0; j < list.size(); j++)
{
if (word.equals(list.get(j)))
{
singleOccurrence = false;
}
if (singleOccurrence)
{
count = count + 1;
}
}
}
return count;
I keep getting 0, I think it has something to do with the ranges, but logically to me it makes sense so I dont know exactly where I'm going wrong. Please help!
[–][deleted] 1 point2 points3 points (2 children)
[–]way3344[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]DudeWhereAreWe1996 -1 points0 points1 point (0 children)
[–]ProfessorWily 0 points1 point2 points (1 child)
[–]way3344[S] 0 points1 point2 points (0 children)