How to compare numbers in vector list?

-2

I have an integer vector list in java (ArrayList ListVet).

public static ArrayList<Integer> ListVet;

And I need to make a comparison between two numbers in that same vector list. So I did like this:

for (int i=0; i<ListVet.size();i++)

{

      if (ListVet[i] > ListVet[i+1])

      {

      }             

}

However, this error occurred:

  

Multiple markers at this line

     
  • The type of the expression must be an array type but it is resolved to ArrayList
  •   

Why did you cause this error? Thank you.

    
asked by anonymous 20.11.2018 / 04:49

1 answer

3

ArrayList is an object, and because in Java you can not override operators like [] to access the list position, you have to use methods, that is, ListVet.get(i) > ListVet.get(i+1)

If you create an array that has a static size, such as Integer[] ListVet , then you will access it with ListVet[i] .

    
20.11.2018 / 04:58