【问题标题】:Using an interger Arraylist to extract words from a string使用整数 Arraylist 从字符串中提取单词
【发布时间】:2017-01-12 05:18:20
【问题描述】:

如何使用提取数组列表来获取文本字符串中该索引处的单词?

ArrayList<Interger> extract = new ArrayList<Interger>();

extract.add(22); extract.add(37);

String text ="How do I get the this word? And this word?";

结果应该是(word,word)

【问题讨论】:

  • 你的问题对我来说没有意义。
  • 整数?这没有意义(正如@ScaryWombat 指出的那样),这个问题也没有。如果您需要认真的帮助,请提出一个严重的问题,一个没有草率的代码,一个有真实的代码,一个告诉您问题的详细信息。
  • 另外,您已经收到了对上一个问题的多个回复,您还没有回复,也没有投票或接受任何回复。如果您只是要忽略以前的所有帮助,为什么要提供帮助?
  • 我得到了问题..w 是字符串文本中的索引 22。 OP 想要提取索引 22 处的单词并将其添加到列表中。 ArrayList 并不意味着您必须为此编写代码。
  • @Pramod 所以你认为这意味着 我如何提取所有以 w 开头的单词

标签: java arraylist indexing


【解决方案1】:
List<String> words = new ArrayList<>();
for (int index : extract) {
    words.add(text.substring(index).split("\\b")[0]);
}
System.out.println(words);
// [word, word]

【讨论】:

    猜你喜欢
    • 2021-03-15
    • 1970-01-01
    • 2012-05-27
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-29
    相关资源
    最近更新 更多