Android intercepts strings

Source: Internet
Author: User

Java code
1. String str = "a = 111, B = 222, c = 333 ";
2. Extract "a = 111"

Method 1: Use the split method
Java code
1. String spStr [] = str. split (",");
2. System. out. println (spStr [0]);
3.

Method 2: Use StringTokenizer
Java code
1. String str = "asdasd _ = 123 + 123 ";
2. String split = "_ + = ";
3. StringTokenizer token = new StringTokenizer (str, split );
4. while (token. hasMoreTokens ()){
5. System. out. println (token. nextToken ());
6 .}
7.

Comparison between the two:
Split all the String methods into string.
1. Memory usage.
2. There is no control method, for example, is there any way to break down something? This is unknown.
StringTokenizer does not have the preceding disadvantages.
Conclusion: StringTokernizer is more professional.


From mixer_a

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.