1

Having problems using 2 dimensional arrays. I have something like this:

List<List<String>> pmValues = new ArrayList<List<String>>();
List<String> pmList = new ArrayList<String>();

I want to add values from pmValues based on the index of pmList if it is equal to another value (layerrate):

for (something) {
    String layerrate = Something;
    String value = Something;

    for (int aa = 0; aa < pmList.size(); aa++) {
        int abc = aa;
        String abc2 = pmList.get(aa);
        for (int bb = 0; bb < pmValues.size(); bb++) {
            if (layerRate.contentEquals(abc2)) {
                pmValues.add(bb, value);   --> it doesnt save??? error
            }
        }
    }
}

I need something like this, I ran the code but seems not working as I need to get the index of pmList to use it to save the values from pmValues in the same index as pmList.

pmList: A
pmValues (values): A1, A2, A3, A4
pmList: B
pmValues (values): B1, B2, B3, B4
pmList: C
pmValues (values): C1, C2, C3, C4

Anyone have any idea? ty

1
  • 5
    what is the point of List<List<String>>, if you want to map A to A1,A2.. then why not use Map<String, List<String>> Commented Jul 1, 2014 at 4:54

1 Answer 1

2

If I follow your question you need to get the inner List,

pmValues.add(bb, value);

should be something like,

if (pmValues.get(aa) == null) {
  pmValues.set(aa, new ArrayList<String>());
}
pmValues.get(aa).add(bb, value);
Sign up to request clarification or add additional context in comments.

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.