package niu.cheng4;
/*
* String类的转换功能
* public byte[] getBytes()把字符串转化成字节数组。
* public char[] toCharArray()将此字符串转换为一个新的字符数组。
* public static String valueOf(char[] data)返回 char 把字符数组转化成字符串
* public static String valueOf(int i)把任意类型的返回 int 参数的字符串表示形式。
* public String toLowerCase()使用默认语言环境的规则将此 String 中的所有字符都转换为小写。
* public String toUpperCase()使用默认语言环境的规则将此 String 中的所有字符都转换为大写。
* public String concat(String str)将指定字符串连接到此字符串的结尾。(把字符串拼接)
*/
public class StringDemo1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s="IloveYou";
//public byte[] getBytes()把字符串转化成字节数组。
byte[] b=s.getBytes();
for(int x=0;x<b.length;x++){
System.out.print(b[x]+" ");
}
System.out.println();//73 108 111 118 101 89 111 117
System.out.println("---------------");
//public char[] toCharArray()将此字符串转换为一个新的字符数组。
char[] c=s.toCharArray();
for(int x=0;x<c.length;x++){
System.out.print(c[x]+" ");
}
System.out.println();//I l o v e Y o u
System.out.println("---------------");
//public static String valueOf(char[] data)把字符数组转化成字符串
String ss=String.valueOf(c);
System.out.println(ss);//IloveYou
System.out.println("---------------");
//public static String valueOf(int i)把任意类型的返回 int 参数的字符串表示形式。
int x=100;
String sss=String.valueOf(x);
System.out.println(sss);//字符串 1 0 0
System.out.println("---------------");
//public String toLowerCase()使用默认语言环境的规则将此 String 中的所有字符都转换为小写。
System.out.println(s.toLowerCase());//iloveyou
System.out.println("---------------");
//public String toUpperCase()使用默认语言环境的规则将此 String 中的所有字符都转换为大写。
System.out.println(s.toUpperCase());//ILOVEYOU
System.out.println("---------------");
//public String concat(String str)字符串连接到此字符串的结尾。(把字符串拼接)
String a="fuck";
String a1="you";
String a2=a+a1;
System.out.println(a2);//fuckyou
System.out.println("---------------");
String a3=a.concat(a1);
System.out.println(a3);//fuckyou
}
}
/*
* String类的转换功能
* public byte[] getBytes()把字符串转化成字节数组。
* public char[] toCharArray()将此字符串转换为一个新的字符数组。
* public static String valueOf(char[] data)返回 char 把字符数组转化成字符串
* public static String valueOf(int i)把任意类型的返回 int 参数的字符串表示形式。
* public String toLowerCase()使用默认语言环境的规则将此 String 中的所有字符都转换为小写。
* public String toUpperCase()使用默认语言环境的规则将此 String 中的所有字符都转换为大写。
* public String concat(String str)将指定字符串连接到此字符串的结尾。(把字符串拼接)
*/
public class StringDemo1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s="IloveYou";
//public byte[] getBytes()把字符串转化成字节数组。
byte[] b=s.getBytes();
for(int x=0;x<b.length;x++){
System.out.print(b[x]+" ");
}
System.out.println();//73 108 111 118 101 89 111 117
System.out.println("---------------");
//public char[] toCharArray()将此字符串转换为一个新的字符数组。
char[] c=s.toCharArray();
for(int x=0;x<c.length;x++){
System.out.print(c[x]+" ");
}
System.out.println();//I l o v e Y o u
System.out.println("---------------");
//public static String valueOf(char[] data)把字符数组转化成字符串
String ss=String.valueOf(c);
System.out.println(ss);//IloveYou
System.out.println("---------------");
//public static String valueOf(int i)把任意类型的返回 int 参数的字符串表示形式。
int x=100;
String sss=String.valueOf(x);
System.out.println(sss);//字符串 1 0 0
System.out.println("---------------");
//public String toLowerCase()使用默认语言环境的规则将此 String 中的所有字符都转换为小写。
System.out.println(s.toLowerCase());//iloveyou
System.out.println("---------------");
//public String toUpperCase()使用默认语言环境的规则将此 String 中的所有字符都转换为大写。
System.out.println(s.toUpperCase());//ILOVEYOU
System.out.println("---------------");
//public String concat(String str)字符串连接到此字符串的结尾。(把字符串拼接)
String a="fuck";
String a1="you";
String a2=a+a1;
System.out.println(a2);//fuckyou
System.out.println("---------------");
String a3=a.concat(a1);
System.out.println(a3);//fuckyou
}
}