This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

List<ArrayList<String>> compile error

 
albert kao
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Siddhesh Deodhar
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.. 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.
 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help this compile error "Syntax error on token "<", [ expected".
Thanks.
List<ArrayList<String>> alerts = new ArrayList<new ArrayList<String>()>();

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50216
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic