Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34275

Re: Working with an array of TreeSet

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Working with an array of TreeSet
Date Tue, 10 May 2016 08:03:40 -0400
Organization A noiseless patient Spider
Lines 32
Message-ID <ngsig9$om1$2@dont-email.me> (permalink)
References <87lh3ijg9u.fsf@Equus.decebal.nl>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Tue, 10 May 2016 12:00:09 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="25281"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+lFdXMPXkjRSBzCmzBmpp8"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0
In-Reply-To <87lh3ijg9u.fsf@Equus.decebal.nl>
Cancel-Lock sha1:6Byzalfu/WpfmrLZlCEoKpT5u20=
Xref csiph.com comp.lang.java.programmer:34275

Show key headers only | View raw


On 5/10/2016 7:37 AM, Cecil Westerhof wrote:
> I would like to have an array of TreeSet<Integer>. But that is not
> possible in Java.
> So I use:
>     TreeSet<?>[] allNodes;
> I fill this with:
>     for (int i = 1; i < maxNode; ++i) {
>         allNodes[i] = new TreeSet<Integer>();
>     }
>
> And to add an Integer I use:
>     @SuppressWarnings("unchecked")
>     private static void addConnection(int from, int to) {
>         TreeSet<Integer> treeSet;
>
>         treeSet = (TreeSet<Integer>) allNodes[from];
>         treeSet.add(to);
>     }
>
> Is this a correct way of doing this, or is there a better way?

     Evading the issue, you might instead try

	BitSet[] allNodes;

... but this (1) won't work for negative values, (2) will work
poorly with widely-scattered values, and (3) doesn't generalize
to other element types.  Nonetheless ....

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Working with an array of TreeSet Cecil Westerhof <Cecil@decebal.nl> - 2016-05-10 13:37 +0200
  Re: Working with an array of TreeSet Eric Douglas <e.d.programmer@gmail.com> - 2016-05-10 04:52 -0700
    Re: Working with an array of TreeSet Cecil Westerhof <Cecil@decebal.nl> - 2016-05-10 15:07 +0200
  Re: Working with an array of TreeSet Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-10 08:03 -0400
  Re: Working with an array of TreeSet Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-05-10 18:19 +0200
    Re: Working with an array of TreeSet Cecil Westerhof <Cecil@decebal.nl> - 2016-05-10 23:22 +0200
      Re: Working with an array of TreeSet Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-10 20:14 -0400
        Re: Working with an array of TreeSet Cecil Westerhof <Cecil@decebal.nl> - 2016-05-11 09:05 +0200
          Re: Working with an array of TreeSet FredK <fred.l.kleinschmidt@gmail.com> - 2016-05-11 14:33 -0700
            Re: Working with an array of TreeSet Lew <lewbloch@gmail.com> - 2016-05-11 14:45 -0700

csiph-web