Java-lang-character-tostring-char
提供:Dev Guides
Java.lang.Character.toString()メソッド
説明
- java.lang.Character.toString(char c)*は、指定されたcharを表すStringオブジェクトを返します。 結果は、指定された文字のみで構成される長さ1の文字列です。
宣言
以下は* java.lang.Character.toString()*メソッドの宣言です
public static String toString(char c)
パラメーター
*c* -変換される文字
戻り値
このメソッドは、指定された文字の文字列表現を返します。
例外
NA
例
次の例は、lang.Character.toString()メソッドの使用法を示しています。
package com.finddevguides;
import java.lang.*;
public class CharacterDemo {
public static void main(String[] args) {
//create 2 char primitives ch1, ch2
char ch1, ch2;
//assign values to ch1, ch2
ch1 = 'V';
ch2 = 115;
//create 2 String objects s1, s2
String s1, s2;
//assign String values of ch1, ch2 to s1, s2
s1 = Character.toString(ch1);
s2 = Character.toString(ch2);
String str1 = "String value of " + ch1 + " is " + s1;
String str2 = "String value of " + ch2 + " is " + s2;
//print s1, s2 values
System.out.println( str1 );
System.out.println( str2 );
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
String value of V is V
String value of s is s