-6

How to check value and its position are same in 2 array list wi?.

Example:

//These should be not equal.
ArrayList<String> listA = {"a", "b", "c"}
ArrayList<String> listB = {"b", "c", "a"}

In this example element are not same position in both array list so return false.. How to check same value in same position without using for loop

I want to expected result this if.

    //These should be equal.
ArrayList<String> listA = {"a", "b", "c"}
ArrayList<String> listB = {"a", "b", "c"}

this type array list then return true because the value and position are same in both array..

4
  • return listA.equals(listB). If you don't like for loop, use while Commented May 6, 2015 at 7:26
  • Check this question Comparing arrays of different sizes without any loop Commented May 6, 2015 at 7:26
  • hehee @Qiu seems an academic question, i guess Arrays.equals is cheatting :D Commented May 6, 2015 at 7:27
  • Voting to reopen, since anwer to this question is going to be significantly different from answers to the duped question, as Matlab and java are completely different languages. Commented May 6, 2015 at 8:20

1 Answer 1

3

use

return listA.equals(listB);

Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal.

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.