How-to articles, tricks, and solutions about INT

Convert boolean to int in Java

To convert a boolean value to an integer in Java, you can use the intValue() method of the java.lang.Boolean class, or you can use a conditional operator.

Convert int to char in java

To convert an int value to a char value in Java, you can use the char type's conversion method, (char).

Determine if a String is an Integer in Java

To determine if a string is an integer in Java, you can use the isDigit() method of the Character class to check if each character in the string is a digit. Here's an example:

How can I prevent java.lang.NumberFormatException: For input string: "N/A"?

java.lang.NumberFormatException: For input string: "N/A" occurs when you try to parse a string that cannot be converted to a number, such as the string "N/A".

How do I convert from int to Long in Java?

To convert an int to a long in Java, you can simply use the typecast operator (long) and place it in front of the value you want to convert.

How to check if an int is a null

In Java, an int is a primitive data type and cannot be null.

How to convert float to int with Java

To convert a float to an int in Java, you can use the (int) type cast operator. The (int) operator will truncate the decimal part of the float value and convert it to an int.

Java Array Sort descending?

To sort an array in descending order in Java, you can use the Arrays.sort method and pass it a comparator that compares the elements in reverse order.

Java int to String - Integer.toString(i) vs new Integer(i).toString()

In Java, there are several ways to convert an int value to a String:

Java: parse int value from a char

To parse an integer value from a char in Java, you can use the Character.getNumericValue() method.