字符串的字符串IntStream - Java [英] IntStream of chars to Strings - Java

查看:170
本文介绍了字符串的字符串IntStream - Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将字符流 str.chars()转换为使用字符串流,其中每个字符串包含5个字符,例如?

Is it possible to convert stream of chars str.chars() to stream with Strings, where each String contains 5 characters, for example?

推荐答案

我不认为尝试组合字符中的元素非常适合Java流而不使用某些第三方库。

I don't think trying to combine elements from the characters is a good fit for Java streams without using some third party libraries.

如果你想要一个包含5个字符子串的流,我会将它们拆分成这样:

If you want a stream of 5 character substrings I would split them like this:

String s = "1234567890123456789012345678901234567890";
IntStream.range(0, s.length()/5)
        .mapToObj(i -> s.substring(i*5, (i+1)*5))
        .forEach(System.out::println);

这篇关于字符串的字符串IntStream - Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆