Java type conversion

What is type conversion?

As the name implies, type conversion means converting to a type different from the originally defined type. For example, I want to convert int type to double type! I think there is (or vice versa).

Type conversion type

The former is

int num1 = 10;
double num2;
num2 = num1;

It will be. Type conversion that is just assigned is called "implicit type conversion". There is also a reverse pattern, but if you do the following, you will get an error.

double num1 = 3.14;
int num2;
num2 = num1;

This is because the range of double type is narrower than that of int type, which may reduce the accuracy. If you want to do this type conversion, do the following: However, the numbers after the decimal point are truncated.

double num1 = 3.14;
int num2;
num2 = (int)num1;

Recommended Posts

Java type conversion
[Java] Date type conversion
[Java] List type / Array type conversion
[Java] Precautions for type conversion
[Java] Type conversion speed comparison
Java Primer Series (Type Conversion)
[JAVA] Stream type
[Java] Enumeration type
Java Optional type
Java double type
Java-automatic type conversion
Java date data type conversion (Date, Calendar, String)
[Easy-to-understand explanation! ] Reference type type conversion in Java
[Java ~ Variable definition, type conversion ~] Study memo
Java study # 3 (type conversion and instruction execution)
[Basic knowledge of Java] About type conversion
Java 8 LocalDateTime type conversion stuff (String, java.util.Date)
[Java] Calculation mechanism, operators and type conversion
Type conversion from java BigDecimal type to String type
[Java] Full-width ⇔ half-width conversion
[Java] Data type ①-Basic type
Uri → String, String → Uri type conversion
[Java, Kotlin] Type Variance
Java class type field
Type determination in Java
Java study # 1 (typical type)
[Java] About enum type
Endian conversion with JAVA
[Introduction to Java] About type conversion (cast, promotion)
Java type conversion (String, int, Date, Calendar, etc.)
Java learning memo (data type)
Try functional type in Java! ①
Java study # 7 (branch syntax type)
Java
Java
[Java Bronze] Learning memo (interface, static method, type conversion, etc.)
[Java] Data type / matrix product (AOJ ⑧ Matrix product)
java (use class type for field)
[Java] Correct comparison of String type
[Java] Conversion from array to List
Java array / list / stream mutual conversion list
Java8 list conversion with Stream map
How to use Java enum type
[Java] Express Enum type without using Enum (enumeration) type
Java learning (0)
[Java Siler] About type inference by var
Studying Java ―― 3
[Java] array
Conversion between Kotlin nullable and Java Optional
Java protected
[Java] Annotation
[Java] Module
Java array
[Java] Implicit type cast (AOJ10-sum of numbers)
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Full-width → half-width conversion with Java String (full-width kana → half-width kana)
Java methods
Java method
java (constructor)