class toStringText
{
private int a = 10;
private float b = 10.0f;
private double d = 100.0d;
public static void main(String[] args)
{
int a = 10;
float b = 10.0f;
double d = 100.000000d;
char[] ch = {'h','e','l','l','o'};
System.out.println(String.valueOf(a));
System.out.println(String.valueOf(b));
System.out.println(String.valueOf(d));
System.out.println(String.valueOf(ch,2,3));
boolean bool = false;
System.out.println(String.valueOf(bool));
System.out.println(bool);
String str = " hello world! ";
System.out.println(str.trim()); //忽略字符串中的前部空格和後部空格
System.out.println(str.toUpperCase());//轉化爲大寫
System.out.println(str.toLowerCase());//小寫
char[] ch2 = str.toCharArray(); //字符串轉化爲字符數組
System.out.println(str.trim().startsWith("hello"));
}
}
java中String的基本用法
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.