Java String Split by Line split(String line, String separator)

Here you can find the source of split(String line, String separator)

Description

split

License

Open Source License

Declaration

public static final String[] split(String line, String separator) 

Method Source Code

//package com.java2s;
/**/*from   www  .  j a va 2  s.  co m*/
  * Copyright 2010 ZTEsoft Inc. All Rights Reserved.
  *
  * This software is the proprietary information of ZTEsoft Inc.
  * Use is subject to license terms.
  * 
  * $Tracker List
  * 
  * $TaskId: $ $Date: 9:24:36 AM (May 9, 2008) $comments: create 
  * $TaskId: $ $Date: 3:56:36 PM (SEP 13, 2010) $comments: upgrade jvm to jvm1.5 
  *  
  *  
  */

import java.util.*;

public class Main {

    public static final String[] split(String line, String separator) {
        LinkedList<String> list = new LinkedList<String>();
        if (line != null) {
            int start = 0;
            int end = 0;
            int separatorLen = separator.length();
            while ((end = line.indexOf(separator, start)) >= 0) {
                list.add(line.substring(start, end));
                start = end + separatorLen;
            }
            if (start < line.length()) {
                list.add(line.substring(start, line.length()));
            }
        }
        return (String[]) list.toArray(new String[list.size()]);
    }
}

Related

  1. split(String line, char delimiter)
  2. split(String line, char delimiter)
  3. split(String line, String delimiter)
  4. split(String line, String regex)
  5. split(String line, String separator)
  6. split(String line, String separator)
  7. split(String line, String separator)
  8. split(String line, String seperator)
  9. Split(String line, String sptr)