Need help on iterating over a list - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need help on iterating over a list

jwbutlerjwbutler Posts: 16Member
I have a object that returns a java.util.List of recordset objects.

The recordset object is a class with five properties and their getter and setter methods.

The code I'm using:

List employeeInfo = Employees.getEmployeeInfo();
ListIterator iterator = employeeInfo.listIterator();
while(iterator.hasNext){
.
.
.
}

I want to be able to retrieve the objects in the list one at a time and use the getter methods to manuipulate the data. All the examples I've seen use single dimetional arrays for List objects.

Thanks,
John

Comments

  • Iceman24Iceman24 Posts: 119Member
    : I have a object that returns a java.util.List of recordset objects.
    :
    : The recordset object is a class with five properties and their getter and setter methods.
    :
    : The code I'm using:
    :
    : List employeeInfo = Employees.getEmployeeInfo();
    : ListIterator iterator = employeeInfo.listIterator();
    : while(iterator.hasNext){
    : .
    : .
    : .
    : }
    :
    : I want to be able to retrieve the objects in the list one at a time and use the getter methods to manuipulate the data. All the examples I've seen use single dimetional arrays for List objects.
    :
    : Thanks,
    : John
    :

    You're pretty much there (I'm using a for loop here simply because it's more compact; your while works just as well):
    [code]
    RecordSet rs;
    List employeeInfo = Employees.getEmployeeInfo();
    for( ListIterator iterator = employeeInfo.listIterator(); iterator.hasNext();){
    rs = (RecordSet)(iterator.getNext());
    //Manipulation here...
    }
    [/code]

    If you're using the 1.5.0 API you could just create the List using generics (RecordsSet as the class) and not have to worry about the typecast. But this way still works more nicely :)

    Hope this helps.


    Iceman


    Efficiency:
    rawIn=(rawIn=(rawIn=br.readLine()).split("href="")[1]).split(""")[0];

  • jwbutlerjwbutler Posts: 16Member
    Iceman,
    Am I using the wrong List object? The iterator object only has one getter method and that is getClass(). The imports I amd using are java.util.List and java.util.ListIterator from j2sdk1.4.2_05.

    : : I have a object that returns a java.util.List of recordset objects.
    : :
    : : The recordset object is a class with five properties and their getter and setter methods.
    : :
    : : The code I'm using:
    : :
    : : List employeeInfo = Employees.getEmployeeInfo();
    : : ListIterator iterator = employeeInfo.listIterator();
    : : while(iterator.hasNext){
    : : .
    : : .
    : : .
    : : }
    : :
    : : I want to be able to retrieve the objects in the list one at a time and use the getter methods to manuipulate the data. All the examples I've seen use single dimetional arrays for List objects.
    : :
    : : Thanks,
    : : John
    : :
    :
    : You're pretty much there (I'm using a for loop here simply because it's more compact; your while works just as well):
    : [code]
    : RecordSet rs;
    : List employeeInfo = Employees.getEmployeeInfo();
    : for( ListIterator iterator = employeeInfo.listIterator(); iterator.hasNext();){
    : rs = (RecordSet)(iterator.getNext());
    : //Manipulation here...
    : }
    : [/code]
    :
    : If you're using the 1.5.0 API you could just create the List using generics (RecordsSet as the class) and not have to worry about the typecast. But this way still works more nicely :)
    :
    : Hope this helps.
    :
    :
    : Iceman
    :
    :
    : Efficiency:
    : rawIn=(rawIn=(rawIn=br.readLine()).split("href="")[1]).split(""")[0];
    :
    :

Sign In or Register to comment.