Java Question Write a Static method that accepts a List<T> argument. It should r
ID: 3759782 • Letter: J
Question
Java QuestionWrite a Static method that accepts a List<T> argument. It should return the number in the list that are equal to the element that comes before it.returning list object after comparing a given object. use only iterators to inspect the list. Do not use for loops or the get() method Java Question
Write a Static method that accepts a List<T> argument. It should return the number in the list that are equal to the element that comes before it.returning list object after comparing a given object. use only iterators to inspect the list. Do not use for loops or the get() method Java Question
Write a Static method that accepts a List<T> argument. It should return the number in the list that are equal to the element that comes before it.returning list object after comparing a given object. use only iterators to inspect the list. Do not use for loops or the get() method
Explanation / Answer
public static <T> int count(List<T> l){
Iterator<T> iterator = l.iterator();
int count = 0;
while (iterator.hasNext()) {
String temp = iterator.toString();
if(temp.equals(iterator.next())) count++;
}
return count;
}