String类转换功能

/*
 * 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]);
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值