• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

List<ArrayList<String>> compile error

 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>()>();

 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic