Object-Oriented 15.2String class-constructor

Source: Internet
Author: User

public class String_constructor {

Shortcut key Small method: Ctrl+d, delete the whole line, select a few lines to delete a few lines
public static void Main (string[] args) {
String S=new string ();//string s= ""; This 2 is the same meaning, equivalent.
Although the address is not the same, but the content is the same, is to construct a string. String S=null; This is not the same, this means that the constant value is null
//
///*
* Converts a byte array into a string
// * */
byte [] arr={65,66,67,68};
String S1=new string (arr);
System.out.println ("s1=" +s1);//abcd, will he assi the numbers? The value is looked up, and a byte array is converted into a string.
/*
* String construction method inside the API help document
* String (char[] value) assigns a new string that represents the sequence of characters currently contained in the character array parameter. (Array of strings)
*
*
* */
Char [] arr={' w ', ' A ', ' P ', ' Q ', ' X '};
String S=new string (arr,1,3),//starting from the 1-point index of the array, taking 3 (starting from 0)
System.out.println (s);
}
}

Object-Oriented 15.2String class-constructor

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.