gpt4 book ai didi

java - 在没有 apache 库的情况下根据空格将行分割成字符串

转载 作者:行者123 更新时间:2023-12-02 02:30:19 25 4
gpt4 key购买 nike

我想根据字符串之间的空格将缓冲读取器中的一行拆分为字符串数组。

BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line;

我知道 apache 库中的一种方法允许您使用

String[] words = StringUtils.split(line);

这是测试练习,我无法访问任何外部库。如何仅使用JDK来执行此操作。

最佳答案

你可以这样做:

String words[] = line.split(" ");

注意 split 调用中的空格。我希望这会有所帮助。

关于java - 在没有 apache 库的情况下根据空格将行分割成字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47230155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com