05 of the hands-on brain in Java

Source: Internet
Author: User

hands on Brain 1:

The result is:

Analysis:"=" Determines whether two objects are the same (stored address and stored content)

theequalsfunction determines whether the values of the two objects are equal

Length (),charAt (), getChars () of the String class, Replace (), touppercase () , tolowercase (),trim () ,tochararray () instructions for use:

1.string.length () is used to find the length of the string, and the return value is the length of the string.

Length ():p ublic int Length ()// Find string length

String s= "DWFSDFWFSADF";

System.out.println (S.length ());

2.string.charat () is a character that takes a position in the string, starting with 0 , for example, string.charat (0) returns the first character of the string.

CharAt ():p ublic charAt (int index)//index is a character subscript that returns the character at the specified position in the string

String s= "Hello";

System.out.println (S.charat (3));

3.string.getchars () copies the characters in this string to the target character array.

GetChars ():p ublic int getChars ()// copy character from this string to the target character array

String str= "Abcdefghikl";

Char[] Ch=new char[8];

Str.getchars (2,5,ch,0);

4.string.replace () replaces the element or substring in the original string. Returns the replaced string.

Replace ():p ublic int replace ()// Replace string

String s="\\\";

System.out.println(s.replace ("\\\","// "));

results ///;

5.string.touppercase () to capitalize the characters in string strings .

Touppecase ():p ublic string toUpperCase ()// convert all strings to uppercase

System.out.println (New String ("hello"). toUpperCase ());

6.string.tolowercase () changes the character in string to lowercase.

toLowerCase ():p ublic string toLowerCase ()// convert all strings to lowercase

System.out.println (New String ("HELLO"). toLowerCase ());

7.string.trim () is a space to remove the string's header.

Trim ():p ublic String trim ()

String x="ax C";

System.out.println (X.trim ());// is the way to go on both sides of the space

8.string.tochararray () converts a string to a character array.

ToCharArray (): String x="abcd";// converts characters in a string object to a single character array

Char Mychar[]=x.tochararray ();

System.out.println ("mychar[1]"+mychar[1]);

05 of the hands-on brain in Java

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.