Use of the split () function and the trim () function in Java

Source: Internet
Author: User
Tags split trim

The split () function splits a string string, returns an array of string (string[]) based on parameters such as ",", "-", "", and so on, and can specify elements by index.

If not found, the entire string string is returned as the No. 0 element of the string array (string[]).

The trim () function is to remove the trailing space of a string string;

Code:

/** 
 * @author Spike 
 * @time 2014.4.25
/public class Split {public  
          
    static void split () {  
        String Details = "M 2.9-9km W of Alberto Oviedo Mota, Mexico";   
        String magnitudestring = Details.split ("") [1];  
        System.out.println (magnitudestring);  
        Details = Details.split (",") [1].trim ();  
        SYSTEM.OUT.PRINTLN (details);  
    public static void Main (string[] args) {  
        //TODO auto-generated method Stub  
        split ();  
    }  
      

Output:

2.9  
Mexico

Author: csdn Blog spike_king

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/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.