1.trim()
Scanner scanner=new Scanner(System.in);
String s=scanner.nextLine();
//s=" SherlyHan "
s.trim();
//s="SherlyHan" 去掉String首尾的空格
2.常见类型转换
(1)String->int
int s1=Integer.parseInt(string);
int s1=Integer.valueOf(string).intValue();
//int s1=Integer.valueOf(string);也是对的
(2)int->String
int i=1;
String s=String.valueOf(i);//int i不被初始化,String 不能进行强制转换
String s=Integer.toString(i);
Stirng s=""+i;
(3.1)String->Integer
Integer integer=Integer.valueOf(string);
(3.2)Integer->String
Integer inte;
String s=inte.toString();
(4)Integer类->int变量名
int i=integer.intValue();
(5)int->Integer
int i;
Integer integer=new Integer(i);
(6)String->char
String s;
char[] ch=s.toCharArray();
ch.get(0);//只有一个char时
(7)char->String
String s=ch.toString();
3.
判断String是否相等:string.equals(S);
4.IO
(1)FileOutputStream out=new FileOutputStream(file);
out.write(string.getBytes());
(2)FileInputStream in=new FileInputStream(file);
int i=in.read();
while(i!=-1)
{
//得到的是编码
i=in.read();
}
(3)BufferedReader br=new BufferedReader(new FileReader(f));
String line;
whie((line=br.readLine()) != null)
System.out.println(line);
(4)DataOutputStream dos=new DataOutputStream(new FileOutputStream(f));
dos.writeInt(string.gertBytes().length);
DataInputStream dis=new DataInputStream(new FileInputStream(f));
byte[] buf=new byte[100];
int len=dis.readInt();
dis.read(buf,0,len);
(5)ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(f));
oos.writeobject(al.get(i));//ArrayList<type> al=new ArrayList();
ObjectInputStream ois=new ObjectInputStream9new FileInputStream(f));
object=(type)ois.readObject();//强制类型转化
5.collection
HashMap.containsKey(key);
6.抽象类
abstract calss Myclass<T>{
protected abstract T peek();
}