Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How does JAVA convert list.get(i) into an integer and compare the size with the integer?
How does JAVA convert list.get(i) into an integer and compare the size with the integer?
First, when you initialize your list, you will have two forms.

1 list & LTE> list = new ArrayList & LTE> ();

2 List List = new ArrayList();

Represents the type of elements in a linked list.

You can play with strings, integers, anything.

If it doesn't matter what e is, e is an object by default.

But if you put int in e, the reason for the error must be very simple. Int is a basic type, which means that the problem is very simple.

This e element must be of encapsulation type. You think it's right because you don't know enough about java data types.

Let me just talk about your mistakes in those two code segments, 1.

((Integer)list.get(i))。 After intValuelist.get(i) gets an OBJ, it can be directly converted with the encapsulation class, and the converted object is an integer. You have to add an intvalue after it. Do you want to convert the encapsulated class to the base type again? This is obviously an error code.

The second code uses the integer method. Parseint (o) encapsulating the class; Why not just throw list.get(i) into OBJ and convert it into an integer? You still need to do an extra operation to convert OBJ into a string. Please see the obj class under API. Is there a tostring method below? Does it taste good?

If you don't speak well, please pat the brick, and I won't write this code.

LZ, you can write your own package classes and basic types.