Java series Learning (12)-string, java series learning string

Source: Internet
Author: User

Java series Learning (12)-string, java series learning string

1. String Basics

Concept: A string is essentially an object for packaging character arrays. It isJava. lang. String class instance

2. String Constructor

   

public String()

public String(byte[] bytes)

public String(byte[] bytes, int offset, int length)

public String(char[] value)

public String(char[] value, int offset, int count)

public String(String original)

3. String features

(1) string constants and string pools

As long as the content is the same, no matter how many times the program code appears, JVM will only create a String instance and maintain it in the String pool.

[Note] the string written in "" is called a String constant.

(2) unchangeable string

Once a string is created, its content cannot be changed. The following code connects two strings with + and creates an object in practice.

4. Common Methods

4.1 convert a string to a basic type (the method in the basic type in the following method)

   

Byte.parseByte(String s)

Short.parseShort(String s)

Integer.parseInt(String s)

Long.parseLong(String s)

Float.parseFloat(String s)

Float.valueOf(String s)

Double.parseDouble(String s)

Double.valueOf(String s)

4. 2. String Functions

(1) Judgment Function

   

public boolean equals(Object anObject)

public boolean contentEquals(StringBuffer sb)

public boolean contains(CharSequence s)

public boolean startsWith(String prefix, int toffset)

public boolean endsWith(String suffix)

public boolean isEmpty()

(2) Retrieval

   

Public intLength()

Public charCharAt(Int index)

Public intIndexOf(String str)

Public intIndexOf(String str, int fromIndex)

Public intIndexOf(Int ch, int fromIndex )【ch-One character (Unicode code point )]

Public StringSubstring(Int beginIndex)

Public StringSubstring(Int beginIndex, int endIndex)

(3) Conversion Function

   

Public byte []GetBytes()

Public char []ToCharArray()

Public static StringValueOf(Char c) [A length is1String]

Public static StringValueOf(Int I)

Public StringToLowerCase()

Public StringToUpperCase()

Public StringConcat(String str) [connect the specified String to the end of this String]

(4) Other functions

   

A. Replacement Function

Public StringReplace(Char oldChar, char newChar)

Public StringReplace(CharSequence target, CharSequence replacement) [character set is a string]

B. Space Removal

Public StringTrim()

C. dictionary-based comparison

Public intCompareTo(String anotherString) [compare Unicode values based on each character in the String]

Public intCompareToIgnoreCase(String str)

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.