Java 8/9: Can a character in a String be mapped to its indices (using streams)?

后端 未结 4 1675
抹茶落季
抹茶落季 2021-02-12 14:46

Given a String s and a char c, I\'m curious if there exists some method of producing a List list from s (where

4条回答
  •  北海茫月
    2021-02-12 15:33

    ...Or in java-9:

    Stream.of("Hello world!")
                .map(Scanner::new)
                .flatMap(s -> s.findAll("l"))
                .map(mr -> mr.start())
                .forEach(System.out::println);
    

提交回复
热议问题