This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes List<ArrayList<String>>  compile error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "List<ArrayList<String>>  compile error" Watch "List<ArrayList<String>>  compile error" New topic
Author

List<ArrayList<String>> compile error

albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 248
Please help to fix this compile error:

List<ArrayList<String>> l = new List<new ArrayList<String>()>();

Description Resource Path Location Type
Syntax error on token "<", [ expected HwServiceImpl.java /com.mycomp.monitoring.war/src/com/mycomp/monitoring/war/service/impl line 172 Java Problem
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1712
    
  12

One (and it may be the only one, but I'm not sure) problem is you're trying to instantiate an interface(List). You should have an ArrayList or LinkedList (or another class that implements List) on the right side of the expression.

Hope that helps!
Janeice


When you do things right, people won't be sure you've done anything at all.
Siddhesh Deodhar
Ranch Hand

Joined: Mar 05, 2009
Posts: 118
.. but I'm not sure) problem is you're trying to instantiate an interface(List)


why not sure ? It is a problem . You cant instantiate interface.


Good, Better, Best, Don't take rest until, Good becomes Better, and Better becomes Best.
Sidd : (SCJP 6 [90%] )
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1712
    
  12

Siddhesh Deodhar wrote:
.. but I'm not sure) problem is you're trying to instantiate an interface(List)


why not sure ? It is a problem . You cant instantiate interface.


I'm just not sure if it's the ONLY problem
albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 248
Please help this compile error "Syntax error on token "<", [ expected".
Thanks.
List<ArrayList<String>> alerts = new ArrayList<new ArrayList<String>()>();

pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
albert kao wrote:Please help this compile error "Syntax error on token "<", [ expected".
Thanks.
List<ArrayList<String>> alerts = new ArrayList<new ArrayList<String>()>();



What Java version are you compiling with? Is it 1.5 or greater? Do you know how to check?
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1712
    
  12

So you are populating an ArrayList with ArrayLists? I had a feeling that syntax would still not work.

Uhm.... and this is really a guess.... try getting rid of the second "new." I am thinking that to populate the ArrayList of Arraylists you'll have to do something like this:

This might work:


See if that works any better....
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18711
    
    8

albert kao wrote:List<ArrayList<String>> l = new List<new ArrayList<String>()>();


Don't put garbage characters into your type names, the compiler is saying. Try this instead:



What that line of code creates is an ArrayList into which you can store ArrayList<String> objects. You aren't creating any ArrayList<String> objects yet so you don't need a constructor which tries to do that.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
You had too many () in the first code snippet.

Rob Prime points out a better way to initialise that: like thisThat way you can add any type of List, not being restricted to ArrayLists.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: List<ArrayList<String>> compile error