2.1Jcreator开发工具介绍
工作区(jcw)与工程(jcp)
使用类向导创建新类;
使用动态随笔功能自动输入功能
指定Jcreator所使用的JDK
设置第三方提供的Jar包
指定启动运行类及参数
设置多个运行配置环境
3、 String类和StringBuffer类,位于java.lang包中
3.1 String类对象中的内容一旦被初始化就不能再改变。
3.2 StringBuffer类利用封装内容可以改变的字符串。
用toString方法转换成String类型
String=“a”+4+“c”;编译时等效于:
String=new StringBuffer().append(“a”).append(4).append(“c”).toString();
字符串常量(如“hello”)实际上是一种特殊的匿名String对象。比较下面两种情况的差异:
String s1 = “hello”;String s2 = “hello”;
String s1 = new String(“hello”);String s2 = new String(“hello”);
编程实例:逐行读取键盘输入,直到输入内容为“bye”时,结束程序。
代码:
public class Readline {
public static void main(String[] args) {
// TODO: 在这添加你的代码
byte [] buf = new byte[1024];
String strInfo = null;
int pos = 0;
int ch = 0;
while(true)
{
try
{
ch = System.in.read();
}
catch(Exception e)
{
e.printStackTrace();
}
switch(ch)
{
case '/r':
break;
case '/n':
strInfo = new String(buf,0,pos);
if(strInfo.equals("bye"))
{
return;
}
else
{
System.out.println(strInfo);//
pos = 0;
break;
}
default:
buf[pos++] = (byte)ch;
}
}
}
}
3.3String类的常用成员方法:
构造方法:
String(byte[] bytes,int offset,int length)将字节数组bytes的第offset位元素起, 取出length个转换为字符串
equalslgnoreCase方法:不区分大小写的情况;
indexOf(int ch)方法:用于返回一个字符:System.out.println(“hello world”.indexOf(‘o’,5));
substring(int beginIndex)方法System.out.println(“hello world”.substringf(6));从第6个元素开始全部输出
<FONT face=""">substring(int beginIndex,int endIndex)