Construction method of Java_se base--62.string class

Source: Internet
Author: User

Let me start by listing the current construction methods used by beginners

How to construct a String:

String () Creates an empty content string object.
String (byte[] bytes) Constructs a string object using a single byte array
String (byte[] bytes, int offset, int length)
Bytes: The array to decode
Offset: Specifies that the decoding is started from that index value in the array.
Length: to decode multiple elements.

String (char[] value) constructs a string using a character array.
String (char[] value, int offset, int count) uses a character array to construct a string, specifying the starting index value, and the number of characters to use.
String (int[] codepoints,int offset,int count)
String (string original)

public class Demo2 {public static void main (string[] args) {string str = new string ();//Create an empty Content string Object  constructor: string () by Te[] Buf = {97,98,99};str = new String (BUF); Constructs a string object constructor using a single byte array    : String (byte[] bytes) str = new string (buf,1,2);   Constructs a string object using a byte array that specifies the number of index values and decoding to start decoding. The constructors used are: String (byte[] bytes, int offset, int length) char[] arr = {' Ming ', ' Day ', ' yes ', ' holy ', ' Christmas '};str = new String (arr); Use a character array to build a string (    char[] value) str = new string (arr,3,2);//Use String (char[] value, int offset, int count)  Constructor int[] Buf2 = {65,66,67};str = new string (buf2,0,3),//Use String (int[] Codepoints,int offset,int count) constructor str = new S Tring ("abc");//Use the string (string original)   constructor System.out.println ("contents of the string:" +str);}}



AC Penguin: 654249738, and self-taught Exchange group: 517284938

Construction method of Java_se base--62.string class

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.