Some codes that I don't know are collected.

Source: Internet
Author: User

Some codes that I don't know are collected.

1. byte [] data2 = "Welcome! I finally met you! ". GetBytes ();

Convert the content in the String type "" to a byte array directly, using the getBytes method of the String class.

2. String info = new String (byte [], 0, packet. getLength ());

Convert the content in the byte [] array to the String type. The code above indicates that the byte array reads the length of the array from 0, and convert the byte content of the array to the String type.

3.

Public static String RandomString (int length ){
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
Random random = new Random ();
StringBuffer buf = new StringBuffer ();
For (int I = 0; I <length; I ++ ){
Int num = random. nextInt (62 );
Buf. append (str. charAt (num ));
}
Return buf. toString ();
}

The method to generate a random array of length. The StringBuffer and String charAt methods are the same as the two binggo methods that were not used in the previous hard work.

4. Generate a time string in the specified format

Date date = new Date ();
SimpleDateFormat sdf = new SimpleDateFormat ("MM dd, yyyy ");
String s = sdf. format (date );

 

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.