アフィリエイト広告を利用しています
最新記事
カテゴリアーカイブ

広告

posted by fanblog

2018年12月20日

Stringからintへ、intからStringへキャスト

String型からint型へキャスト。

class Demo{
 public static void main(String[] args) {

  String str = "10";

   Integer strInt = Integer.parseInt(str);
   System.out.println(strInt * 2);
 }


===== 実行結果 =====
20
================


次はint型からString型にキャスト。

class Demo{
 public static void main(String[] args) {

  int i = 5;

   String str = Integer.toString(i);
   System.out.println(str);
 }
}

===== 実行結果 =====
5
================

実行結果はint型の時と同じ5だけど
型がString型にキャストされているので演算をすることができない。

地球の末路!?




検索


















×

この広告は30日以上新しい記事の更新がないブログに表示されております。