String的转换功能

来源:互联网 发布:啊哈c语言 小木虫 编辑:程序博客网 时间:2024/05/17 22:45
package StringMethod;
/*
 * String的转换功能
 *public  byte[] getBytes();//把字符串转换成字节数组
 * char[] toCharArray();//把字符串转换成字符数组
 * static String valueOf(char[] chs)//把字符数组转换成字符串
 * static String valueOf(int i)
 * String toLowerCase()//转换成小写的字符串,生成一个新的字符串,原本的并没有发生改变
 * String toUpperCase()\
 * String concat (String str)//拼接字符串,在开发的时候建议还是使用+进行拼接
 */
public class ZhuanHuan
{
public static void main(String[] args)
{
String s1="abcdefg";
byte[] by=s1.getBytes();
for(int i=0;i<s1.length();i++){
 System.out.println(by[i]);
       }
System.out.println("----------------");
char[] ch=s1.toCharArray();
for(int i=0;i<s1.length();i++){
System.out.println(ch[i]);
}
System.out.println("----------------");
char[] ch1={'1','2','3','4','5','6'};
String ss=String.valueOf(ch1);
System.out.println(ss);
System.out.println("----------------");
int i=900;
String sss=String.valueOf(i);
System.out.println(sss);
System.out.println("----------------");
String sd="HelloWorld";
String sd1=sd.toLowerCase();
String sd2=sd.toUpperCase();
System.out.println(sd1);
System.out.println(sd2);
System.out.println("----------------");
String sd3=sd.concat(s1);
System.out.println(sd3);

}
}
0 0
原创粉丝点击