Hi Hunter,
Sorry to take so long in replying to your rapid response to my post. I've been taking some anti-smoking medication that has completely messed-up my sleep cycle, as well as my thought processes. A sorry excuse I know, but the only one I have
"The varenicline did it - not me".
What I want to do should, I feel, be quite simple (meaning, quite simple for me to solve on my own - but I've been at this for most of the day):
- Iterate item by item over the arraylist that I already have (arData)
- Check whether the first item in the arraylist has a first element that is the same as the one in the previous iteration
- If the same, then just append the item - in this case an array of data (array of Strings), to an arraylist called arListDay
- If different, then copy/write/do
somethingwith the arraylist (arListDay) that has been created, in order to store it in another arraylist called arListLocation
The answer is most probably enormously simple - just right at the moment I simply can't see it, for whatever reason. I used to consider myself a fairly handy programmer (about ten years ago & in VB 4-6) - but Java is fairly new to me, OO too, and I can't see a means of copying the contents of arListDay to arListLocation, and then clearing the contents of arListDay, ready for it to receive data that pertains to a new day (without clearing from arListLocation the copy of the data that has just been made to it in the process).
OK - I can see the problem is to do with objects
An arraylist is an object (as just about everything is in Java
). I'm adding that object (arListDay) to another arraylist (& object) (arListLocation), and then simply saying "arListDay.clear();" - which is obviously going to not just clear the 'surface' "arListDay", but also the "arListDay" that has just been added to the arListLocation. That's my problem!
Should I use some method like clone() to make a copy of the arraylist arListDay, then add the copy to arListLocation, prior to clearing the contents of arListDay? I take it that if I do then that is a "deep copy" - and so expensive, plus what happens when I create (when the next day's data has been stored in arListDay) and I use clone again - wont that simply overwrite the previous addition to arListLocation? - what I really just want to do is (if there were such a thing) a 'copy' 'byVal' - in order to just get a completely new arraylist that I can then simply append to arListLocation (call it arListDay1) and then empty arListDay using clear(). Then empty arListDay1.
Subsequently, I could just loop through the code in my first post - and refill arListDay, before adding more data from it (or it's copy (arListDay1) to arListLocation).
I hope this helps explain my problem (edited to add - probably not - I just reread the above and didn't underststand it myself! I'll repost in the morning) - or maybe explain why I'm having the problem :) I've been awake now, thanks to the GP prescribed anti-smoking medication, for 36 hours - and am having huge problems concentrating.
Thanks again for any replies
ETA - see second last paragraph above.
Don.