字符串和字符
来源:互联网 发布:声道测试软件 编辑:程序博客网 时间:2024/05/20 09:26
String提供9个构造函数,以不同的方式来初始化String对象。以下代码展示了六个方法:
public class StringConstructors
...{
public static void main(String args[])...{
char charArray[] = ...{'b','i','r','t','h',' ','d','a','y'};
byte byteArray[] = ...{(byte)'n',(byte)'e',(byte)'w',(byte)' ',(byte)'y',(byte)'e',(byte)'a',(byte)'r'};
String s = new String("Hello");
String s1 = new String();
String s2 = new String(s);
String s3 = new String(charArray);
String s4 = new String(charArray,6,3);
String s5 = new String(byteArray,4,4);
String s6 = new String(byteArray);
String output = "s1 = " + s1 + " s2 = " + s2 + " s2 = " + s2 + " s3 = " + s3 + " s4 = " + s4 + " s5 = " + s5 + " s6 = " + s6 ;
JOptionPane.showMessageDialog(null,output,
"String Class Constructors", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
};
...{
public static void main(String args[])...{
char charArray[] = ...{'b','i','r','t','h',' ','d','a','y'};
byte byteArray[] = ...{(byte)'n',(byte)'e',(byte)'w',(byte)' ',(byte)'y',(byte)'e',(byte)'a',(byte)'r'};
String s = new String("Hello");
String s1 = new String();
String s2 = new String(s);
String s3 = new String(charArray);
String s4 = new String(charArray,6,3);
String s5 = new String(byteArray,4,4);
String s6 = new String(byteArray);
String output = "s1 = " + s1 + " s2 = " + s2 + " s2 = " + s2 + " s3 = " + s3 + " s4 = " + s4 + " s5 = " + s5 + " s6 = " + s6 ;
JOptionPane.showMessageDialog(null,output,
"String Class Constructors", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
};
1,字符转换:Integer.parseInt();
2,字符串连接:String s = new String("Good");
String u = new String("Night");
System.out.println(s.concat(u));
3,大小写转换:String toLowerCase(); String toUpperCase();
4,删除首位空格:String trim();
5,字符串反转:StringBuffer s = new StringBuffer("123456");
System.out.println(s.reverse());
6,将StringBuffer转换成String;
StringBuffer s = new StringBuffer("abcdeg");
String s2 = s.toString();
- 字符串和字符
- 字符数组和字符串
- 字符数组和字符串
- 字符数组和字符串
- 字符数组和字符串
- Lisp.字符串和字符
- 字符和字符串
- 字符和字符串
- 字符串和字符函数
- 字符和字符串处理
- 字符串,字符和字节
- 字符串和字符数组
- 字符串和字符
- Swift--字符串和字符
- Swift--字符串和字符
- Swift字符串和字符
- Swift-字符串和字符
- 字符串和字符数组
- tomcat的用户名和密码定义文件
- 用STL流操作文件
- DatagridView取字段值賦給textbox,搞出一個奇怪的值﹗﹗
- RoboCup平台安装问题和解答~~
- 程序员的十大级别--看看你是哪个级别
- 字符串和字符
- Oracle日期格式
- 谈由VMM在运行时为GUEST OS 中给定进程打PATCH的方法
- Memory-mapped I/O and port-mapped I/O
- 来增加的博客添加下新文章。
- ICMP协议
- “易语言.飞扬”集成开发环境(IDE)现状
- 项目日志 2007.08.08-需求分析3
- 2008-8-8倒计时365天