Data Types
The following table lists the primitive types in Rust and their equivalent in Java:
Rust | Java | Java Wrapper Class | Note |
---|---|---|---|
bool | boolean | Boolean | |
char | char | Character | See note 1. |
i8 | byte | Byte | |
i16 | short | Short | |
i32 | int | Integer | See note 2. |
i64 | long | Long | |
i128 | |||
isize | See note 3. | ||
u8 | |||
u16 | |||
u32 | |||
u64 | |||
u128 | |||
usize | See note 3. | ||
f32 | float | Float | |
f64 | double | Double | |
() | void | Void | See note 4. |
Notes:
-
char
in Rust andCharacter
in JVM have different definitions. In Rust, achar
is 4 bytes wide that is a Unicode scalar value, but in the Java Platform, aCharacter
is 2 bytes wide (16-bit fixed-width) and stores the character using the UTF-16 encoding. For more information, see the Rustchar
documentation. -
Unlike Java (and like C/C++/C#), Rust makes a distinction between signed and unsigned integer types. While all integral types in Java represent signed numbers, Rust provides both signed (e.g.
i32
) and unsigned (e.g.u32
) integer types. -
Rust also provides the
isize
andusize
types that depend on the architecture of the machine your program is running on: 64 bits if you're on a 64-bit architecture and 32 bits if you're on a 32-bit architecture. -
While a unit
()
(an empty tuple) in Rust is an expressible value, the closest cousin in Java would bevoid
to represent nothing.
See also: