Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   an Array of ArrayLists in Java 5 (http://www.velocityreviews.com/forums/t139222-an-array-of-arraylists-in-java-5-a.html)

Gary Newell 12-13-2004 11:25 PM

an Array of ArrayLists in Java 5
 
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



Ryan Stewart 12-14-2004 12:10 AM

Re: an Array of ArrayLists in Java 5
 
"Gary Newell" <nospam@intel.com> wrote in message
news:cpl8dh$80n$1@news01.intel.com...
[...]
> 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 12-14-2004 03:32 PM

Re: an Array of ArrayLists in Java 5
 
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" <zzanNOtozz@gSPAMo.com> wrote in message
news:1vydnX0boubxsiPcRVn-pw@texas.net...
> "Gary Newell" <nospam@intel.com> wrote in message
> news:cpl8dh$80n$1@news01.intel.com...
> [...]
> > 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];
>
>





All times are GMT. The time now is 01:14 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.