String Class Fetch functionality

Source: Internet
Author: User

The Get function of the string class: Packagecom.itheima_04;/** Get function of String class: * int Length (): Gets the length of the string, which is actually the number of characters * char charAt (int index): Gets the character at the specified index * int indexOf (String str): Get str The first occurrence of the index in a string object * string substring (int start): Intercepts the string from start * string substring (int start,int end): Starts from start and ends with the end of the intercept string. Includes start, not including end*/ Public classStringdemo { Public Static voidMain (string[] args) {//creating a String ObjectString s = "HelloWorld"; //int Length (): Gets the length of the string, which is actually the number of charactersSystem.out.println (S.length ()); System.out.println ("--------"); //char charAt (int index): Gets the character at the specified indexSystem.out.println (S.charat (0)); System.out.println (S.charat (1)); System.out.println ("--------"); //int indexOf (string str): Gets the index of the first occurrence of STR in a string objectSystem.out.println (S.indexof ("L")); System.out.println (S.indexof ("Owo")); System.out.println (S.indexof ("AK")); System.out.println ("--------"); //string substring (int start): Intercepts a string from startSystem.out.println (s.substring (0)); System.out.println (S.substring (5)); System.out.println ("--------"); //string substring (int start,int end): Intercepts a string from start to endSystem.out.println (s.substring (0, S.length ())); System.out.println (S.substring (3,8)); }}

The comparison between characters is ultimately a comparison of their corresponding integers in the ASCII code table.

String Class Fetch functionality

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.