Here you can find the source of split(final String s, final char separator)
separator
and trims spaces if present.
Parameter | Description |
---|---|
s | incoming string |
separator | separator character |
public static String[] split(final String s, final char separator)
//package com.java2s; /* Copyright 2002 Health Level Seven, Inc. All Rights Reserved. * * This software is the proprietary information of Health Level Seven, Inc. * Use is subject to license terms.// ww w . j a v a 2 s.com */ import java.util.ArrayList; import java.util.List; public class Main { /** * Splits a String at character <code>separator</code> and trims spaces * if present. * * @param s incoming string * @param separator separator character * @return an array of tokens found */ public static String[] split(final String s, final char separator) { if (s == null) return null; final List<String> result = new ArrayList<String>(); int j = -1; for (int i = s.indexOf(separator); i != -1; j = i, i = s.indexOf(separator, i + 1)) { result.add(s.substring(j + 1, i).trim()); } result.add(s.substring(j + 1).trim()); return result.toArray(new String[result.size()]); } }