Java String Tokens

  • + 0 comments
    // Write your code here.
            String trimmed=s.trim();
            String[] tokens = trimmed.split("[ !,?._'@]+");
            int tokenCount=0;
            for(String token: tokens){
                if(!token.isEmpty()){
                    tokenCount++;
                }
            }
            System.out.println(tokenCount);
            for (String token : tokens) {
                System.out.println(token);
            }