Java - Convert sentence to word List

Description

Convert sentence to word List

Demo

//package com.book2s;
import java.util.List;
import java.util.stream.Stream;
import java.util.stream.Collectors;
import java.util.List;

public class Main {
    public static void main(String[] argv) {
        String context = "this is a test";
        System.out.println(toList(context));
    }/*  w  w  w.jav a 2 s. com*/

    static public List<String> toList(String context) {
        return toList(context, "\\s+");
    }

    static public List<String> toList(String context, String str) {
        return Stream.of(context.split(str)).collect(Collectors.toList());
    }
}

Convert sentence to word List

Related Exercise