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

Get list size  RSS feed

 
John Joe
Ranch Hand
Posts: 443
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have multiple query in Java and trying to add them in a list. I can get totalList and l but don't know how to get dataList.


  
JDBC

   
 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On line 19 dataList is being overwritten each time around the loop, so, only the last one will display in your print.
 
John Joe
Ranch Hand
Posts: 443
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:On line 19 dataList is being overwritten each time around the loop, so, only the last one will display in your print.

Is there any way I can get the dataList size and at the same time I can add everything up into list ? Thanks
 
John Joe
Ranch Hand
Posts: 443
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use but get below errors
 
John Joe
Ranch Hand
Posts: 443
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help !
 
Liutauras Vilda
Sheriff
Posts: 4927
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find it difficult to follow your method. Most likely because it does many things. I'd suggest start by decomposing it into smaller pieces (meaning several other methods), and might you'll notice some programming errors of yours yourself. When something doesn't work, always try to decompose/refactor, make it smaller, easier to understand - so you could be sure you didn't introduce a bug. More better of course would be to write right away small methods which clearly expresses intent - that usually saves time in a longer term.
 
Liutauras Vilda
Sheriff
Posts: 4927
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Method names matter a lot.

You got some method named:
getFromText() - I'm wondering what that might be. Get from text what? Character, first one or last one? Maybe amount of characters text contains? Maybe vowels? Maybe user ID? Home address?
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Joe wrote:I use but get below errors

So let's look at the error message and see what we can discern: You're trying to add an element to a List of Object[].  So each element needs to be an Object[].  We don't have the code for getFromText() but from the error we can tell that it returns a List.  So you're trying to add an element to dataList that is a List, but you've defined dataList as a List of Object[].

So you need to decide if you want dataList to be a List of Lists or if getFromText() should return an Object[] instead of a List.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Joe wrote:Please help !

EaseUp
PatienceIsAVirtue
 
John Joe
Ranch Hand
Posts: 443
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm able to solve it

I use addAll instead of add and change the return type of getFromText from List to List<Object[]>
JDBC


 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting the solution, and good job.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!