Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35526
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: ArrayList vs HashMap |
| Date | 2016-08-31 13:05 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <nq72q2$lvl$1@dont-email.me> (permalink) |
| References | (1 earlier) <q08urbp60906u39su1o8feo0i3unlcednp@4ax.com> <136a0364-6810-45b3-9dc0-7a0ac235fef5@googlegroups.com> <2v5csb5sbcsmc8mhl568kddioqa8cntdng@4ax.com> <ArrayList-20160831004938@ram.dialup.fu-berlin.de> <slrnnsdktf.456.avl@login.logic.tuwien.ac.at> |
On 8/31/2016 8:55 AM, Andreas Leitgeb wrote:
> Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>> A HashSet, on the other hand, has a nicer interface for
>> programmers, so one should write an »ArraySet implements Set«
>> wrapper for ArrayLists (unless such a thing should already exist).
>
> Unless I missed something, the interface Set doesn't add any method,
> that isn't already in Collection.
>
> If it weren't for Set's specific semantics of add(o) where o was
> already contained, then ArrayList would "already be a Set".
There's also the matter of equals() and hashCode() semantics:
Set<String> s1 = new HashSet<>();
Set<String> s2 = new TreeSet<>();
s1.add("Hello"); s1.add("World");
s2.add("World"); s2.add("Hello");
assert s1.equals(s2);
assert s1.hashCode() == s2.hashCode();
List<String> l1 = new ArrayList<>();
List<String> l2 = new LinkedList<>();
l1.add("Hello"); l1.add("World");
l2.add("World"); l2.add("Hello");
assert !l1.equals(l2);
assert l1.hashCode() != l2.hashCode(); // probably
--
esosman@comcast-dot-net.invalid
The Tooth Fairy has gone high-tech, now pays in Bitecoin.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
ArrayList vs HashMap Roedy Green <inquiry@mindprod.com> - 2016-08-25 09:42 -0700
Re: ArrayList vs HashMap Roedy Green <inquiry@mindprod.com> - 2016-08-25 09:43 -0700
Re: ArrayList vs HashMap Eric Douglas <e.d.programmer@gmail.com> - 2016-08-25 10:06 -0700
Re: ArrayList vs HashMap Roedy Green <inquiry@mindprod.com> - 2016-08-30 16:34 -0700
Re: ArrayList vs HashMap Andreas Leitgeb <avl@logic.at> - 2016-08-31 12:55 +0000
Re: ArrayList vs HashMap Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-08-31 13:05 -0400
Re: ArrayList vs HashMap Andreas Leitgeb <avl@logic.at> - 2016-08-31 17:34 +0000
Re: ArrayList vs HashMap j4n bur53 <janburse@fastmail.fm> - 2016-08-31 09:15 +0200
csiph-web