21 ways to use String in Java

Source: Internet
Author: User

( constructors must be new )

* public string (char[] Vaue) converts a character array into a string (constructor)

* public string (char[] Vaue,int offset,int count) changes the range of character arrays into strings (constructors)

* public string (byte[],bytes) converts a byte array into a string (constructor)

* public string (byte[],bytes,int offset,int length) converts a byte array into a string (constructor) in the developed range

* Public char[] ToCharArray () converts a string into a character array

* Public char charAt (int index) Remove the top-top position character from a string

* Public byte[] (getBytes) converts a string into a byte array

* public int length () gets the string length

* Public int indexOf (string str) from the beginning to find the specified string position cannot find return-1

* Public int indexOf (string str,int fromIndex) finds the specified string position from the specified location

* Public String trim () clears both left and right spaces

* public string substring (int beginindex) starts from the specified position and fetches the string from the tail

* public string substring (int begin,int end) Specifies the start point and end point of the intercept string

* Public string[] Split (string regex) splits a string according to the specified string

* public string toUpperCase () turns a string all uppercase

* public string toLowerCase () turns a string all lowercase

* Public boolean StartsWith (string prefix) to infer whether to start with a string

* Public boolean EndsWith (string suffix) to infer whether to end with a string

* Public boolean equals (String str) infers whether two strings are equal

* Public boolean equalsignorcase (string str) does not differentiate between uppercase and lowercase strings for equality

* Public string ReplaceAll (string regex,string replacement) string substitution


Example:

public class Strdemos {public static void main (String args[]) {    char[] s={' g ', ' 1 ', ' C ', ' C '};    String Str=null;    Str=new String (s);    System.out.println (str);//Converts a character array into a string            char[]d=str.tochararray ();//Converts a string to a character array for    (int i=0;i< d.length;i++) {    System.out.println (d[i]);}}    Output: g1ccg1cc


21 ways to use String in Java

Related Article

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.