1

This is in Java

I'm not sure what is wrong with the arrayName.length in my code, it doesn't work on both occasions

    for (int i = 0; i<arr.length; i++)
    {
        for(int j = 0; j < arr2.length; j++)
        {

        }
    }

These two arrays are char arrays and does not seem want to work with the .length method. It says that "length cannot be resolved or is not a field"

Can someone please explain to me why this is happening

enter image description here

5
  • 1
    Possible duplicate of .length cannot be resolved or is not a field Commented Nov 8, 2017 at 23:33
  • can you show is more code than this. Commented Nov 8, 2017 at 23:36
  • sry guys, first time asking on stackexchange, image at bottom Commented Nov 8, 2017 at 23:40
  • 2
    it's not an array, it's an ArrayList - you should import it and call the method size() on an instance Commented Nov 8, 2017 at 23:44
  • Nice arc theme. I like it :D Commented Nov 8, 2017 at 23:45

1 Answer 1

3

You aren't using arrays in your code, you are using ArrayLists. They are totally different and have different methods. The equivalent method to length for ArrayList is .size().

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.