Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Is there a better way to group and sort objects? Date: Wed, 8 Aug 2018 06:57:33 -0400 Organization: A noiseless patient Spider Lines: 20 Message-ID: References: <8c045ff4-98c5-4253-9136-b26b34cf8f77@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 8 Aug 2018 10:57:38 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="78e0e0668ea51940846a409d57950007"; logging-data="10047"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ZecUKYSkE5t9pjHtdVe1U" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 Cancel-Lock: sha1:bif3uQQcxXv2dJKgVVu0t9l/xv0= In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.java.programmer:38530 On 8/8/2018 4:20 AM, Martin Gregorie wrote: > On Tue, 07 Aug 2018 06:00:19 -0700, Eric Douglas wrote: > >> I want to combine and sort objects by key properties and merge their >> secondary properties. Is there a better way? This is what I came up >> with.. >> > Given your ..and sort... requirement, I'd use a TreeMap rather than a > HashMap because storing items in key sequence is implicit. In addition, > its search efficiency rises as the tree gets bigger; if the treemap > contains 2**23 entries a worst case search only does 23 key comparisons. ... except that he sorts on a field of the mapped values, not on the map keys. Specifically, if he has two instances with `var1' values of 2 and 10 they will sort in that order, but their map keys will sort in the order "10" followed by "2". -- esosman@comcast-dot-net.invalid Eight hundred ninety-six days to go.