0

I was wondering if there was any way that i could compare and index of an arrayList and a array. I tried using the > operator and that didn't work.

I have tried something like this

if(ArrayVar[i] > arrayList.get(i) )

and i get errors.

6
  • 1
    What do you mean, "compare and index of an arrayList and a array"? Commented Sep 19, 2010 at 20:35
  • arrayList.get(i) and Array[i]. I want to compare and see if one is bigger than the other Commented Sep 19, 2010 at 20:38
  • What is the content of your list and the content of your array ? Commented Sep 19, 2010 at 20:38
  • @Steffan Harris How did it fail ? What are the types of arrayList.get(i) and Array[i] , and what were the actual values ? Commented Sep 19, 2010 at 20:39
  • 1
    you can't compare an Object with an Integer; if you know that the Object is actually an Integer, then you will need to typecast it ((Integer) myObj) then make the comparison. Commented Sep 19, 2010 at 20:44

1 Answer 1

2

You say that the array is of type Object and the arrayList is an Integer type. You are comparing apples and oranges.

Assuming the array acutally holds Integers as their Objects, you can cast that to an Integer and do the comparison then.

If the array doesn't have Integers (or any kind of number) how do you expect to compare them?

Sign up to request clarification or add additional context in comments.

1 Comment

@Steffan, the SO convention is to upvote answers which you find useful (by clicking on the up arrow next to the answer). Since you accepted the answer, you obviously found it useful - please consider upvoting too. I did it now, for justice :-)

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.