Java Sample Code note (Forget point)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.