aspose file tools
The moose likes Beginning Java and the fly likes List<ArrayList<String>>  compile error Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 224
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: 1612
    
  10

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: 117
.. 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: 1612
    
  10

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: 224
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: 1612
    
  10

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: 16483
    
    2

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: 32708
    
    4
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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: List<ArrayList<String>> compile error
 
Similar Threads
Generics Casting
tiger - doubt in this code ...
Generics question
Generics ? extends
Wildcard character