I encountered this error while using the haseNext() method for ArrayLists:
error: cannot find symbol
while(isduplicate == false && birthdays.hasNext())
this is my code:
import java.util.*;
class hello
{
public static void main(String args[])
{
Integer size = 4;
Integer count = 5;
Integer doubleinarray = 0;
for(Integer i = 0 ; i < count ; i++) {
List<Integer> birthdays = new ArrayList<Integer>();
birthdays = CreateSimulator(size);
Integer countdown = size;
boolean isduplicate = false;
while(isduplicate == false && birthdays.hasNext()) {
Integer date = birthdays.get(0);
birthdays.remove(0);
if(birthdays.contains(date)) {
isduplicate = true;
doubleinarray ++;
}
}
}
System.out.println(doubleinarray / count * 100);
}
public static List<Integer> CreateSimulator(int size)
{
List<Integer> Birthdays = new ArrayList<Integer>(size);
Random rand = new Random();
for(Integer i =0 ; i < size ; i++) {
Birthdays.add(rand.nextInt(364) + 1);
}
return Birthdays;
}
}
I didn't understand why it doesn't accept the hasNext. besides this, the rest of the code works fine.
appreciate your help
thanks :)