Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

List  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My issue is with Lists: i have made a query that bring me some results, then i save those results inside of a ArrayList and i want to reuse them to compare them to an other list, but when i call the list again from outside the while it brings me the last register of the query it doesn't shows all the results.

I would like to know what can i do to fix that. Thank you



this.dbSrcServer is the connection to the server that brings the results & I create the List outside to reuse it, in other class or method.

I didn't write the rest of code because it's the query, i just want to know if i did something wrong in here
 
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every time your code cycles-through the outer while loop, it is are creating a new ArrayList object (line 7), discarding the reference to the previous ArrayList, which pointed to the previously added data.
 
nu nin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:Every time your code cycles-through the outer while loop, it is are creating a new ArrayList object (line 7), discarding the reference to the previous ArrayList, which pointed to the previously added data.


ok thank you

I've an other question, it's necesary to iterate after the fields that i need to add, or just adding the fields is ok?
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only need to use List's add method.

Also you probably will want to define a Promotion class with fields for promotionType, promotionName, comment, etc, then work with a List<Promotion> rather than triplets of Strings.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!