Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in ArrayList and Enumeration program. need help please...

 
Siri Naray
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone help me in debugging this code please. Its giving the error saying ; is expected for the end of while condition. I dont understand why.
import java.util.List;
import java.util.List.ArrayList;
import java.util.comparator;
import java.util.collections;
import java.util.Enumeration;

class Student{
private int sno;
private String sname;
Student(int i, String name)
{
sno = i;
sname = name;
}

public int getsno()
{

return sno;

}

public String getName()
{
return Sname;
}
} //end of Student
class ArrayListComparator
{
public static void main(String [] args)
{

List<Student> stu = new ArratList<Student>();
stu.add(new Student(1,"Siri"));
stu.add(new Student(2,"Shiva"));
stu.add(new Student(3,"Shruti"));
stu.add(new Student(4,"Sidd"));

Enumeration<Student> e = stu.elements();
While(e.hasMoreElements()) // giving an error here saying ; is expected
{
Student s = (Person)e.nextElement();
System.out.println("Stu No \t Stu Name");
System.out.println(s.getsno() +"\t" +s.getName());
}
}

Thank you

 
Nitin Surana
Ranch Hand
Posts: 129
Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I debugged your code, there were a large no. of errors like While instead of while, spelling mistakes, illegal imports, wrong methods called i.e. there is nothing like elements() in a List.
I personally suggest, start using a IDE (Netbeans/Eclipse).

Here is your code corrected :

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitin Surana wrote:I debugged your code


Please don't do that. This site is NotACodeMill. The OP won't learn if others do his work for him.
 
Siri Naray
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Nitin. I debugged after correcting "While" to "while" and then it showed all the errors . It was not showing me the errors because of while --after fixing that I could see the many errors I made and could correct it. thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic