Java String Classification Trim,substring,replaceall,indexof usage features

Source: Internet
Author: User

1. Trim Performance

Feature strips the string from the end of the space, preventing unnecessary whitespace from causing an error.

public class Trimtest{public static void Main (string[] args) {String str1= "CJC"; String str2= "C JC"; System.out.println (Str1.length ()); System.out.println (Str1.trim (). Length ()); System.out.println (Str2.length ()); System.out.println (Str2.trim (). Length ());}}


2, substring, replaceall, and indexof functions

Str.substring (n); cut off the first n characters of str;

Str.replaceall ("[AB]", "_"); the characters ' a ' and ' B ' that appear in STR are replaced by ' _ ';

Str.indexof ("good"); if Str contains good, the first letter of the good ' G ' is returned at index position in str (starting from 0).

public class Trimtest{public static void Main (string[] args) {int num; String str1= "CJC is a good//boy!"; System.out.println (STR1); str1=str1.substring (7); System.out.println (STR1); Num=str1.indexof ("good"); SYSTEM.OUT.PRINTLN (num); Str1=str1.replaceall ("[/A]", "_"); System.out.println (STR1);}}



Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Java string Classification Trim,substring,replaceall,indexof use features

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.