Java parsing string splitting individual elements

Source: Internet
Author: User

Sometimes the requirements require multiple string parameters to be passed, but the method parameters are fixed to a single string, and I encounter this problem when I learn the message passing between unity and Android, so I write a method of splitting individual elements into a parsing string.

Example: "@[email protected] @apple"

resolves to:

My

Red

Apple

1  Packagecutstring;2 3 Importjava.util.ArrayList;4 Importjava.util.List;5 ImportJava.util.Scanner;6 /**7  * 8 * @ClassName: MainClass9 * @Description: string format "@[email protected]@c", A,b,c will be parsed as a separate elementTen * @authorLuxishi One * @date March 8, 2016 PM 5:57:56 A * -  */ -  Public classMainClass { the  -      Public Static voidMain (string[] args) { -String m_sentence= "@[email protected] @apple"; -List<string> m_list=cutstring (m_sentence); + System.out.println (M_list.size ()); -           for(String tmp:m_list) { + SYSTEM.OUT.PRINTLN (TMP); A          } at  -     } -   -     StaticList<string>cutstring (String stence) -     { -List<string> stringlist=NewArraylist<string> ();//used to store parsed elements . in          for(intI=0;i<stence.length (); i++) -         { to             if(Stence.charat (i) = = ' @ ') +             {  -String temp= "";//Store Words the                 intWordlength=i; *                  while(Wordlength<stence.length () -1&&stence.charat (++wordlength)! = ' @ ') $                 {Panax Notoginsengtemp+=Stence.charat (wordlength); -                     //System.out.println (temp); the                 } + Stringlist.add (temp); A             } the         } +         returnstringlist;  -     } $}

Java parsing string splitting individual elements

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.