您的位置:首页 > 其它

String类转换功能

2015-06-22 21:59 239 查看
/*
* String类转换功能
*/
public class StringTestTransform {
public static void main(String[] args) {
method_4();
}

/*
* 拼接字符串
* public String concat(String s)
*/
public static void method_4(){
String s = "abc";
// s =s.concat("qq");
s = s +"qq";
System.out.println(s);
}

/*
* 静态的
* 类名直接调用
* static String valueOf(任意)
* 将任意的数据类型变成字符串
*/
public static void method_3(){
int x = 1;
String s = x+"";
// String s =String.valueOf(x);
System.out.println(s);
}

/*
* 字符串的大写,小写转换
* public String toUpperCase() 大写
* public String toLowerCase() 小写
*/
public static void method_2(){
String upper = "abcdedsEfef";
upper = upper.toUpperCase();
System.out.println(upper);

String lower = "dgfDFFfEGFgfe";
lower = lower.toLowerCase();
System.out.println(lower);
}

/*
* 将字符串转成字符数组
* public char[] toCharArray()
* 不查询编码表
* 和构造方法效果,相反效果
*/
public static void method_1(){
char[] ch = "abcde".toCharArray();
for(int x = 0 ; x < ch.length ;x++){
System.out.println(ch[x]);
}
}

/*
* 将字符串转成字节数组
* public byte[] getBytes()
* 查询本机默认的编码表,中文操作系统中GBK
* 和构造方法中的功能,是一个相反效果
*/
public static void method(){
String s = "abcd";
//调用方法 getBytes(),将字符串s,变成字节数组
byte[] bytes = s.getBytes();
for(int x = 0 ; x < bytes.length ;x++){
System.out.println(bytes[x]);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: