String StringBuffer 等、
1、String类代表代表不可变的字符序列。
2、常见构造方法:查询API文档,好多种。
3、当创建一个字符串变量时,若已经存在,则不在分配,而是将新变量指向原有位置。
即为同一个对象。但是当用new方法创建时则为不同对象。
class TestString
{
public static void main(String[] args)
{
String s1 = "Hello";
String s2 = "world";
String s3 = "Hello";
System.out.println(s1 == s3);
s1 = new String("Hello");
s2 = new String("Hello");
System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
}
}
输出为:
True
false
True
String中对equals方法进行重写,内容相同即为true。
4、 public char charAt(int n) 返回第n个字符
s.indexof(xxx) 返回s中第一个出现字符串xxx的位置。
s.startWith("xxx") 返回是否以xxx开始
s.sunstring(int n) 从第n个位置开始截取
等等、、
5、静态重载方法:
valueOf( ) 将基本数据类型转换为string类型。
s.split(“x”) 将字符串按指定的分隔符x分割成一个个字串。
6、java.lang.StringBuffer 代表可变的字符序列。与String类似,但是可以对其字符串进行改变。
7、Math:包装了一系列数学方法。
abs 绝对值 、 sin cos tan等、sqrt 开平方、log 自然对数、pow(a,b) a的b次方、max min random 、round小数部分四舍五入 等等、、、
8、File类:java.io.File 类代表文件系统文件名。
eg:
import java.io.*;
class TestFile
{
public static void main(String[] args)
{
String separator = File.separator;
String name = "end.txt";
String dir = "1" + separator + "2";
File f = new File(dir,name);
if(f.exists())
{
System.out.println("name :" + f.getAbsolutePath());
System.out.println("size :" + f.length());
}
else
{
f.getParentFile().mkdirs();
try{
f.createNewFile();
}catch(IOException e){
e.printStackTrace();
}
}
}
}
9、Enum 枚举类型:
只能取特定值中的一个、 用enum关键字定义、是java.lang.Enum类型
-------------------------------------------------
end、