LoginSignup
30
27

More than 3 years have passed since last update.

kotlinの型と変換

Last updated at Posted at 2017-10-29

kotlinで使える型

数値

ビット幅
Double 64
Float 32
Long 64
Int 32
Short 16
Byte 8

またkotlinでは型を宣言しなくとも実行できるが

val a = 1F + 3

val a = 1L + 3

などでFloat+IntやLong+Intなどの計算ができる。
*Float型はforFでタグ付けをする。

文字

ビット幅
Char 8

文字列

ビット幅
String 可変

真偽値

ビット幅
Boolean 一般に8

配列

ビット幅
Array

型変換

文字列から数値

 val t : String = "123"
 val i : Int = Integer.parseInt(t)

数値から文字列

val a : Int =  32
val s : String = a.toString()

数値から数値

val b  : Float= 3.0F
val f : Int = b.toInt()

数値からの数値への変換は全ての数値型への変換をサポートしています

  • toByte(): Byte
  • toShort(): Short
  • toInt(): Int
  • toLong(): Long
  • toFloat(): Float
  • toDouble(): Double
  • toChar(): Char
30
27
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
27