Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35526
| Path | csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: ArrayList vs HashMap |
| Date | Wed, 31 Aug 2016 13:05:58 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 31 |
| Message-ID | <nq72q2$lvl$1@dont-email.me> (permalink) |
| References | <ps7urbhve2c7lfn0f3nop1p0hkgjsgdaid@4ax.com> <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> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Wed, 31 Aug 2016 17:06:11 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="22517"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fCtoGfJYG5ThWJ8RAkpCF" |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
| In-Reply-To | <slrnnsdktf.456.avl@login.logic.tuwien.ac.at> |
| Cancel-Lock | sha1:mzDuf/QBnwajgeMzaNMS5ZqOn/4= |
| Xref | csiph.com comp.lang.java.programmer:35526 |
Show key headers only | View raw
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