How can I convert a long to int in Java?

To convert a long value to an int value in Java, you can use the intValue method of the java.lang.Long class. This method returns the value of the specified long as an int.

Here's an example of how you can use the intValue method:

long l = 123456789L;
int i = l.intValue();

Alternatively, you can use an explicit type cast to convert a long to an int. However, this can cause a loss of precision if the long value is too large to fit in an int. For example:

long l = 123456789L;
int i = (int)l;

Keep in mind that if the long value is too large to fit in an int, the result of the type cast may not be the same as the original long value.

I hope this helps! Let me know if you have any questions.