0

I keep getting an "identifier expected" when trying to use this statement. Does anyone have an idea why? .get is a method call of arrayList and im just getting an int index and I'm adding a string to that a list inside my arrayList

 ArrayList Obj.get.(index).add(Str);
4
  • Why do you have the word "ArrayList" at the front? Commented Apr 7, 2015 at 16:22
  • Just to show that is my type of object Commented Apr 7, 2015 at 16:23
  • I'm trying to get the index of my inner list inside my array list and add my string to the correct inner list because I have multiple of them Commented Apr 7, 2015 at 16:24
  • can you elaborate more specific? Commented Apr 7, 2015 at 16:28

1 Answer 1

1

Your code has multiple errors.

  • First of all, that line is not declaring a variable, and therefore you don't specify the type (ArrayList).
  • Assuming your variable is called Obj, I would recommend you to call it something meaningful and name variables starting with lower-case letters (same deal with Str).
  • Do not add a dot (.) after the method name (get(index)).

After that, your line should look like this:

list.get(index).add(str);

To give you a better understanding, you can split that line of code in multiple lines:

List<String> subList = mainList.get(index);
subList.add(str);
Sign up to request clarification or add additional context in comments.

3 Comments

It tells me I can not add string to my list(array list) of lists(linkedlists)
Declare em as List and assign em ArrayList and LinkedList, etc
Could clarify what you mean? I don't quite understand.

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.