[英]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.