Re: ArrayList.addAll syntax



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/

.



Relevant Pages

  • Re: Basic list/dictionary question
    ... A simple example with strings doesn't seem to work how I'd expect: ... Python doesn't do any extra copying in most places unless you ... just copies references to the same object and does not copy the object ...
    (comp.lang.python)
  • Re: Dynamic Hash
    ... Please read the documentation on hashes before making assumptions about how they look. ... Perl provides no alternate means of handling the issue. ... The program structures were never strings per-se, in the same sense as data ... This does not get as deeply nested as a directory tree, of course, but you should be able to see how references link together ...
    (perl.beginners)
  • Re: strange linking problem
    ... I usually use C, and since strings ... > files and looks for unsatisfied references to functions and variables. ... then I don't understand how the linker does not either ... that there should be a data area of a certain size and a certain name. ...
    (comp.lang.fortran)
  • Re: Trying to write strncpy() in ASM
    ... Unaligned loads translate into multiple bus accesses, so copying 2 bytes at ... mov al, ... If you are copying long strings then his solution is definitely ...
    (comp.lang.asm.x86)
  • Re: Poincare and Einstein on Relativity
    ... "copying of examples"? ... useful references. ... I don't see anything surprising except that Whittaker was pretty off. ... English translation of a key paper by Poincare. ...
    (sci.physics.relativity)