• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

iterate

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers,

My code



My output :




Can any one help me ..with this output...how can i convert this out put to an arrayList......
 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 46
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Just declare the arraylist object
but arraylist allow duplicates..



hope will use..
 
Sheriff
Posts: 21917
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ritika Misra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator






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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic