Java String Tokens

  • + 0 comments

    import java.io.; import java.util.; import java.util.stream.*;

    public class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        // Write your code here.
    
    
        List<String> token = Arrays.asList(s.split("[ !,?._'@]"))
            .stream()
            .map(x -> x.trim())
            .filter(x -> !x.isEmpty())
            .collect(Collectors.toList());
    
        System.out.println(token.size());
        for (String t: token){
            System.out.println(t);
        }
    
        scan.close();
    }
    

    }