File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes iterate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "iterate" Watch "iterate" New topic
Author

iterate

Ritika Misra
Ranch Hand

Joined: Jun 17, 2009
Posts: 30
Hello ranchers,

My code



My output :




Can any one help me ..with this output...how can i convert this out put to an arrayList......


Java Dev User
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

how can i convert this out put to an arrayList


By looking at your System.out statement and the output,
Just declare an ArrayList of type of the objects you are displaying. Add those objects to the list as you iterate.



Is this what you want?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
prasad guna
Ranch Hand

Joined: Feb 12, 2009
Posts: 43

Hi,

Just declare the arraylist object
but arraylist allow duplicates..



hope will use..


Prasath.G
SCJP
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

prasad guna wrote:Hi,

Just declare the arraylist object
but arraylist allow duplicates..



hope will use..

Just make sure to declare and initialize the array list outside of the loop. Otherwise you will have many array lists, each with only one element, that is ready for garbage collection immediately.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ritika Misra
Ranch Hand

Joined: Jun 17, 2009
Posts: 30
well guys,
i dont want to add it as it is appearing in the output.
I want to add to my data to a POJO first and then that POJO to ArrayList .
Somewat like this ....

POJO Name =Transaction
skeleton


i want to set the value of column id to id ,name to name and so on...
then these each Transcation object to arrayList.

so how do i do this

thanks in advance
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

Well, you have to populate POJOs with the values retrieved from database while iterating the loop and add each of them to the list unless you are using a O/R Mapping framework like Hibernate which will load POJOs for you from the database.
Ritika Misra
Ranch Hand

Joined: Jun 17, 2009
Posts: 30
i know that ..
but as you can see my out put .....
this data which i get...is coming from Access database
so i m not getting in the regular format through which i can populate my POJO..


Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775






What ever you are getting you assigned to a type Object here. What type is that object? Isn't that the type you want (i.e: type of your POJO) ?
Ritika Misra
Ranch Hand

Joined: Jun 17, 2009
Posts: 30
Well Vijitha Kumara,

As you suggest ,
What ever you are getting you assigned to a type Object here. What type is that object? Isn't that the type you want


if i do this,




And this error is valid as it is a linked hashMap ....so please suggest some way out for retreiving data from LinkedHashMap
I get an error ....pasting error below,
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

If that is a Map then you retrieve the values using the keys (as you know the keys are id,name,etc..) and set them in the POJO.



And make sure the types of properties of the POJO match with what you retrieve.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: iterate
 
Similar Threads
ONGL Question
onchange for dynamically added rows
Soda Machine GUI
Jackcess
Castor - ignore elements on Unmarshalling