Re: ArrayList.addAll syntax
- From: "jon23d@xxxxxxxxx" <jon23d@xxxxxxxxx>
- Date: 15 Jul 2006 10:52:59 -0700
Thank you Thomas,
So, if I understand what you are saying then is that I am comparing
disparate objects and not their strings...
[2 minutes later]
Yipee! Thank you very much for helping me learn the solution to this
troubling problem! As to the maps, I was unaware of their existence
until you mentioned them here.... Oh well, it was a good exercise for
me.
Jonathon
Thomas Hawtin wrote:
jon23d@xxxxxxxxx wrote:
Everything works fine, but when I try to call the object's .get method> [...]
after calling .open() I am thrown a NoSuchFieldException. I am certain
that there is something screwed up with the copying of the serialized
ArrayList to the existing one. I have tried looping through, copying,
..copyAll... None seem to work.
[...]
private ArrayList<String[]> preferences;
String[] keyPair = preferences.get(i);
if (keyPair[0]==key) { index = i; }
== on references, such as Strings, tests whether the same object is
refererd to, not whether the referred objects have the same value.
equals should be used here. When the list is deserialised, new Strings
are created which aren't == to your old keys. Similarly if you have a
key of "my-key" and try a lookup with new String("my-key") you will not
find a match.
BTW, why not use a Map of some description?
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
.
- References:
- ArrayList.addAll syntax
- From: jon23d
- Re: ArrayList.addAll syntax
- From: Thomas Hawtin
- ArrayList.addAll syntax
- Prev by Date: Re: listening to several ports at a time
- Next by Date: Re: Multiple monitors and JDialog
- Previous by thread: Re: ArrayList.addAll syntax
- Next by thread: Best site for java
- Index(es):
Relevant Pages
|