• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Arraylist problem

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good Morning (or whatever it may be for you!)

I am trying to add items to an arraylist. I know all about the arrayList.add(). However, the problem I'm running into is that I am using an object to hold the data (its summarization information for a report) of ExpenseItem, and I can't manage to get an arraylist to build properly so that it can be displayed. What I am doing is below:



So, as you can see, I bring in an external array, populate it from the form if data exists in the form, adding data to the array, and then writing it back to the form. It sounds like it should work, but I'm getting some really unexpected results when I do a println off the arrayList. I'm getting something similar to below:



Any ideas on how to make it one consistant arraylist?

Thanks,
-TerriLyn
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ugh; seems like a day object would have made that a little cleaner :(If getWeekInfo() returns a list (which the poorly-named wIc implies) you're adding a list into a list, producing a nested list. You may be thinking of java.util.Collection's addAll(...) method.

Additionally:Besides both comments being redundant, the first comment is also plain wrong and misleading.
 
Terri Layman
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David,

Thanks for looking at it, but I think I may have sorted it out.

At the point in the code that calls the "storeValues()" I changed how the array is constructed.



At that point it constructs the array that gets passed to the storeValues. It also checks to see if the arraylist in the form is empty, if it's not it overrides the inital construction of the arraylist with the constructor that loads it from the form.

Then in the storeValues(), I'm getting the "Week Info Count" (your referenced badly named wIc). That gives me the position where to add another object (WCI) to the "overall" arraylist. I then set the arraylist in the form to the value of the new "local" arraylist.



Make sense?

Now if I could only get it to STOP re-appending the new data to the arraylist once the summary page is drawn, should the user hit the refresh button or some such, life would be golden, and I'd be down to format clean up.

Thanks for looking!

-Terri
 
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic