1.trim ()
Scanner scanner=new Scanner (system.in);
String S=scanner.nextline ();
S= "Sherlyhan"
S.trim ();
s= "Sherlyhan" strips the string from the leading and trailing spaces
2. Common Type Conversions
(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 is not initialized, string cannot be cast
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 class->int variable name
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);//When there is only one char
(7) Char->string
String s=ch.tostring ();
3.
Determine if the string is equal: 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)
{
What you get is code.
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 ();//Forced type conversion
5.collection
Hashmap.containskey (key);
6. Abstract class
Abstract CALSS myclass<t>{
Protected abstract T peek ();
}
Java Sample Code note (Forget point)