Re: Is there a way to use String[] as a Set??
- From: Thomas Hawtin <usenet@xxxxxxxxxxxxxxxxx>
- Date: Fri, 30 Sep 2005 09:44:26 +0100
Ingo R. Homann wrote:
Hi Roedy,
Roedy Green wrote:
Arrays.asList(strs)
What actually pops out, I know it is a List, but is it an ArrayList really or some minimalist wrapping around the original array without making a copy?
IIR the Sources correctly, it is a minimalist wrapping class that implements List. IIRC, even add() is not possible but throws an UnsupportedException.
Sources are a good place to look.
Yup, no structural modifications allowed, although you can use set. It only requires a single, tiny little object with a single reference (plus header) to be allocated, much like an iterator. In this day and age the cost of allocating a small object is more or less negligible. For comparison, javac's code for concatenating two strings creates at least four objects (it could use String.concat instead).
The clue (without looking at the docs or source) that it is a live wrapper rather than a copy, is that the method name is asList, not toList.
Tom Hawtin -- Unemployed English Java programmer http://jroller.com/page/tackline/ .
- Follow-Ups:
- Re: Is there a way to use String[] as a Set??
- From: Roedy Green
- Re: Is there a way to use String[] as a Set??
- References:
- Re: Is there a way to use String[] as a Set??
- From: Thomas Hawtin
- Re: Is there a way to use String[] as a Set??
- From: Ingo R. Homann
- Re: Is there a way to use String[] as a Set??
- Prev by Date: Re: Under Linux, Call java from C++
- Next by Date: JAR, JNI and libraries
- Previous by thread: Re: Is there a way to use String[] as a Set??
- Next by thread: Re: Is there a way to use String[] as a Set??
- Index(es):