KBD

Keith Devens .com

Wednesday, December 3, 2008 Flag waving
A language that doesn't affect the way you think about programming, is not worth knowing. – Alan Perlis
← President Bush's speechForbidden thoughts about 9/11 →

Daily link icon Thursday, September 12, 2002

Java in a Nutshell

Java in a Nutshell is a fantastic book. If you use Java, you must get it. Hey, look at that, a fourth edition is out, curses!

Hmm, is there any way to turn an array of a primitive type into a Collection? Or at least automatically turn an array of a primitive type into an array of one of the "wrapper" types so that I can turn it into a List with java.util.Arrays.asList.

Grr, never mind. Even that won't do what I want, because I can't turn a List into a Map. Looks like I'll have to use java.lang.reflect.Array to do my dirty work.

← President Bush's speechForbidden thoughts about 9/11 →

Comments XML gif

Pholser wrote:

PrimitiveArrays {
  private PrimitiveArrays() {
  }

  public static List asList( final int[] primitives ) {
    return new AbstractList() {
      private int[] backingStore = primitives;

      public Object get( int index ) {
        return new Integer( backingStore[ index ] );
      }

      public Object set( int index, Object item ) {
        Object previousItem = get( index );
        backingStore[ index ] = ((Integer) item).intValue();
        return previousItem;
      }

      public int size() {
        return backingStore.length;
      }
    };
  }
}
∴ Pholser | 2-Dec-2003 1:31pm est | #3406

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

December 2008
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 5 posts

Recent comments XML

new⇒Girls, please don't get breast implants

I have 34 A breast but at 22 years​old they seem to be growing again​which ...

76.64.120.153: Dec 3, 10:00am

Perl 6 1.0 in March?

Doh, my mistake. I'm aware of the​relation between Parrot and Rakudo​but I'...

Keith: Dec 2, 1:03am

Free image hosting sites

Well, TinyPic has this in its​FAQ:

> Images and videos is in​your accoun...

Keith: Dec 1, 1:13am

Join a NameValueCollection into a querystring in C#

Well with a lamba expression, this​is what I came up​with:

?!code:csharp...

Gustaf Lindqvist: Nov 30, 4:38pm

Why no generic OrderedDictionary?

Check​http://www.codeproject.com/KB/recip​es/GenericOrderedDictionary.aspx?d...

Gabrielk: Nov 27, 6:57am

Generated in about 0.963s.

(Used 8 db queries)

mobile phone