簡體   English   中英

使用整數 Arraylist 從字符串中提取單詞

[英]Using an interger Arraylist to extract words from a string

如何使用提取數組列表來獲取文本字符串中該索引處的單詞?

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)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM