aspose file tools*
The moose likes Java in General and the fly likes Error in ArrayList and Enumeration program. need help please... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Error in ArrayList and Enumeration program. need help please..." Watch "Error in ArrayList and Enumeration program. need help please..." New topic
Author

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

Siri Naray
Ranch Hand

Joined: May 19, 2006
Posts: 105
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

Joined: Jan 21, 2011
Posts: 129

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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: May 19, 2006
Posts: 105
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error in ArrayList and Enumeration program. need help please...
 
Similar Threads
please clear me to display
Confusion about a question
problem with hibernate
facing problem while creating JPA namedQuery
Problem whne used custom squence name in JPA (hibernate) annotations