0

I'm working on a java project and i want to create a list of Maps that the type of keys is Character and the values are ArrayLists of Characters. I have written something like this :

List<Map<Character, ArrayList<Character>>>

but the eclipse says : Syntax error on token ">>>", VariableDeclarator expected after this token

How can i do it ? any idea ?

4
  • can you post a bit more code? Commented Mar 25, 2013 at 18:45
  • 1
    Instead of a List<Map<Character, ArrayList<Character>>> I'd write some classes representing your data. After all, Java is an OOP language. You'll get self describing and easy to maintain code. Right now, your heading into a mess. Commented Mar 25, 2013 at 18:47
  • can you include the whole line of code where you are declaring List<Map<Character, ArrayList<Character>>>? Commented Mar 25, 2013 at 18:51
  • I think the compiler error is just informaing you that you need to supply the name of the variable. Commented Mar 25, 2013 at 18:59

3 Answers 3

8

The compiler is expecting a variable name to comply with Java syntax:

List<Map<Character, List<Character>>> myList = 
                              new ArrayList<Map<Character, List<Character>>>();
Sign up to request clarification or add additional context in comments.

5 Comments

I might +1 IF this turns out to be the actual issue
This is correct. You could also have List<Map<Character, ArrayList<Character>>> myList; and define myList later.
Why i can't have an array of Maps ? (instead of using List)
@Kozet - You could use an array of Maps, but it would be much better to use a list.
You can also use List<Map<Character, List<Character>>> = new ArrayList<Map<Character, List<Character>>>();
0

List<Map<Character, ArrayList<Character>>> list ; should be given

see the screen shot below

enter image description here

Comments

0

You can declare a variable as an interface (e.g. List) but to create an instance, you must choose an implementation (e.g. ArrayList):

List<Map<Character, ArrayList<Character>>> myList = new ArrayList<Map<Character, ArrayList<Character>>>();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.