Java String Tokens

  • + 0 comments

    import java.io.; import java.util.; /* *@Author : Rehan *Using Stream API in Java8 */ public class SolutionDump {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        scan.close();
        if (s.trim().length()==0 || s.trim().length()>400000){
        System.out.println(0);
        return;
        }
        s=s.trim();
        // Write your code here.
        List<String> count = Stream
        .of(s.split("[^(a-zA-Z)]+")).collect(Collectors.toList());
    
        System.out.println(count.size());
                //to print the expected list
        \Stream.of(s.split("[^(a-zA-Z)]+")).forEach(System.out::println);
    
    }
    

    }