Java String Tokens

  • + 0 comments

    import java.util.*;

    public class Solution {

    public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine(); tokens(str); } public static void tokens(String s){ s = s.trim(); String[] words = s.split("\P{L}+");

    if (s.length() == 0){
        System.out.println(0);
    }
    else{
        System.out.println(words.length);
    }
    for (String token:words){
        System.out.println(token);
    }
    

    } }