-3

I am currently working on the list concepts of apex and working on this piece of code:

List<Integer> ages = New List<Integer>();
ages.add(10);
ages.add(20);
List<Integer> one = New List<Integer>();
ages.add(10);
ages.add(20);
Boolean b = ages.equals(one);
system.debug('Equals: ' +b);

My expectation for the debug should be

true

true. However, when I check it - I am getting

false

Could anybody help me?

  • 2
    Considering you posted a question on this site tagged with Apex in 2016, it is untruthful to say you are new to development. Even if it were true, it would still be completely irrelevant. – Adrian Larson May 7 '18 at 16:58
3

The lists are not equal; you added four values to ages, and none to one. It looks like you meant to do this:

List<Integer> ages = New List<Integer>();
ages.add(10);
ages.add(20);
List<Integer> one = New List<Integer>();
one.add(10);
one.add(20);
Boolean b = ages.equals(one);
system.debug('Equals: ' +b);
  • @abhi If this answer works for you please remember to "accept" it by selecting the check mark next to the answer. This way, other uses with similar questions will know which answer was correct. – gNerb May 7 '18 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.