一、String类
(1)使用字符串常量直接初始化一个String对象 语法格式:
String 变量名=字符串;
通过构造方法初始化字符串对象:
public class Example{
public static void main(String[ ]args){
String str1=new String;
String str2=new String(“abc”);
String str3=new String(charArray);
System.out.println(“a”+str1+“b”);
System.out.println(str2);
System.out.println(str3);
}
}
(2)Strin
g 类的常用方法
int indexOf (int ch)返回指定字符在字符串的位置
char charAt(int index) 返回字符串中index位置上的字符
int length() 返回字符串长度
boolean startsWith(String prefix) 判断字符串是否以指定的字符串开始
String toLowerCase() 将String中所有字符转换成小写
String toUpperCase() 将String中所有字符转换成大写
String substring(int begin Index)下标从0开始截取方法
String trim() 去除字符串首尾空格
二、 StringBuffer 类
(1)概念:构造一个不带字符串的缓冲区
(2)StringBuffer 类常用方法
stringBeuffer append( )添加字符到末尾
方法的具体用法:
public class Example{
public static void main(String args[ ]){
System.out.printlnl(“1.添加”);
add();
System.out.printlnl(“2.修改”);
update();
System.out.printlnl(“3.删除”);
delete();
}
}
三、 Date类
用于表示日期和时间的类
Date类用法:
import Java.util.*;
public class Example{
public static void main(String [] args){
Date date1=new Date();
Date date2=new Date(System.currenTimeMillis()+1000);
System.out.println(“date1”);
System.out.println(“date2”);
}
}