Java String Tokens

  • + 0 comments

    // worked

    import java.util.Arrays; import java.util.Scanner;

    public class Solution {

    public static void main(String[] args) {

    Scanner in = new Scanner(System.in);
    String s = in.nextLine();
    
    String[] tokens = s.split("[ !,?._'@]+");
    tokens = Arrays.stream(tokens).filter(token -> !token.isBlank()).toArray(String[]::new);
    
    System.out.println(tokens.length);
    for (String token : tokens) System.out.println(token);
    

    } }