an Array of ArrayLists in Java 5

Discussion in 'Java' started by Gary Newell, Dec 13, 2004.

  1. Gary Newell

    Gary Newell Guest

    Hi -

    I need some Java 5 help. The following code snippet worked fine in Java
    1.4.2.

    I'm setting up an array of ArrayLists. Each ArrayList contains Doubles.
    The following code is generating a compiler time warning.

    code:
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    import java.util.*;

    public class arrayOfArrayLists {

    public static void main(String args[]) {

    ArrayList arrayListDoubles[] = new ArrayList [ 5 ];

    for( int j=0; j<arrayListDoubles.length; j++ ) {
    arrayListDoubles[ j ] = new ArrayList<Double> ();
    }

    // start loading values into the first arraylist
    arrayListDoubles[0].add( new Double( "100" ) );
    }
    }
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    compiler warning:
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    C:\temp>javac -d . -Xlint:unchecked *.java
    arrayOfArrayLists.java:13: warning: [unchecked] unchecked call to add(E) as
    a member of the raw type java.util.ArrayList
    arrayListDoubles[0].add( new Double( "100" ) );
    - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Any idea how to get each of the ArrayLists in the Array to be expecting
    Doubles?

    Thanks!!

    Gary
    Gary Newell, Dec 13, 2004
    #1
    1. Advertising

  2. Gary Newell

    Ryan Stewart Guest

    "Gary Newell" <> wrote in message
    news:cpl8dh$80n$...
    [...]
    > ArrayList arrayListDoubles[] = new ArrayList [ 5 ];

    [...]
    > arrayListDoubles[0].add( new Double( "100" ) );

    [...]
    > - - - - - - - - - - - - - - - - - - - - - - - - - - -
    > C:\temp>javac -d . -Xlint:unchecked *.java
    > arrayOfArrayLists.java:13: warning: [unchecked] unchecked call to add(E)
    > as
    > a member of the raw type java.util.ArrayList
    > arrayListDoubles[0].add( new Double( "100" ) );
    > - - - - - - - - - - - - - - - - - - - - - - - - - - -
    >

    Specify a type for the ArrayList:
    ArrayList<Double>[] arrayListDoubles = new ArrayList<Double>[5];
    Ryan Stewart, Dec 14, 2004
    #2
    1. Advertising

  3. Gary Newell

    Gary Newell Guest

    Ryan -

    Both of these generate compile time errors:
    ArrayList<Double>[] arrayListDoubles = new ArrayList<Double> [ 5 ];
    and
    ArrayList<Double> arrayListDoubles[] = new ArrayList<Double> [ 5 ];

    Errors (respectively):
    C:\temp>javac arrayOfArrayLists.java
    arrayOfArrayLists.java:7: generic array creation
    ArrayList<Double>[] arrayListDoubles = new ArrayList<Double>
    [ 5 ];
    ^
    1 error

    C:\temp>javac arrayOfArrayLists.java
    arrayOfArrayLists.java:7: generic array creation
    ArrayList<Double> arrayListDoubles[] = new ArrayList<Double>
    [ 5 ];
    ^
    1 error


    Any ideas?

    Gary



    "Ryan Stewart" <> wrote in message
    news:...
    > "Gary Newell" <> wrote in message
    > news:cpl8dh$80n$...
    > [...]
    > > ArrayList arrayListDoubles[] = new ArrayList [ 5 ];

    > [...]
    > > arrayListDoubles[0].add( new Double( "100" ) );

    > [...]
    > > - - - - - - - - - - - - - - - - - - - - - - - - - - -
    > > C:\temp>javac -d . -Xlint:unchecked *.java
    > > arrayOfArrayLists.java:13: warning: [unchecked] unchecked call to add(E)
    > > as
    > > a member of the raw type java.util.ArrayList
    > > arrayListDoubles[0].add( new Double( "100" ) );
    > > - - - - - - - - - - - - - - - - - - - - - - - - - - -
    > >

    > Specify a type for the ArrayList:
    > ArrayList<Double>[] arrayListDoubles = new ArrayList<Double>[5];
    >
    >
    Gary Newell, Dec 14, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UG9udGlNYXg=?=

    ArrayList of ArrayLists: How to implement IEnumerable

    =?Utf-8?B?UG9udGlNYXg=?=, Jul 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    421
    =?Utf-8?B?UG9udGlNYXg=?=
    Jul 5, 2004
  2. standshik
    Replies:
    2
    Views:
    14,731
    N Mulangi
    Feb 11, 2006
  3. Weasley

    Usage of Arraylists in Java

    Weasley, Dec 9, 2009, in forum: Java
    Replies:
    3
    Views:
    420
    Roedy Green
    Dec 9, 2009
  4. Ross
    Replies:
    11
    Views:
    867
    Mike Schilling
    Jul 7, 2010
  5. Weasley

    Arrays and Arraylists in Java

    Weasley, Dec 9, 2009, in forum: Javascript
    Replies:
    1
    Views:
    99
    Michael Haufe (\TNO\)
    Dec 9, 2009
Loading...

Share This Page