Java String Slice slice(String line)

Here you can find the source of slice(String line)

Description

Turns a line with strings separated by one or more spaces into a String array.

License

Open Source License

Parameter

Parameter Description
line The line to be sliced

Return

A String array with the slices

Declaration

public static String[] slice(String line) 

Method Source Code

//package com.java2s;
/*/*  www  .j  a  v a  2s.com*/
 * Mentawai Web Framework http://mentawai.lohis.com.br/
 * Copyright (C) 2005  Sergio Oliveira Jr. (sergio.oliveira.jr@gmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

public class Main {
    /**
     * Turns a line with strings separated by one
     * or more spaces into a String array.
     * 
     * @param line The line to be sliced
     * @return A String array with the slices
     */
    public static String[] slice(String line) {
        return line.trim().split("\\s+");
    }

    public static String[] split(String line) {
        String[] s = new String[line.length()];

        for (int i = 0; i < line.length(); i++) {
            s[i] = String.valueOf(line.charAt(i));
        }
        return s;
    }
}

Related

  1. slice(int theNum, String[] theStringArray)
  2. slice(String contents, int CONTENT_COLUMN_SIZE)
  3. slice(String input, int index, int length)
  4. slice(String value, int beginOffset, int endOffset, boolean trim)
  5. sliceAndMatch(String fstring, String rstring)
  6. sliceLength(int start, int stop, long step)