0
我有一個文本文件。該特定文本文件的示例內容就像正則表達式提取鍵值對
root(ROOT-0, good-4)nn(management-2, company-1)nsubj(good-4, management-2)
現在我需要將它分開並將其存儲在ArrayList中。爲此我寫下面的代碼
public class subject {
public void getsub(String f){
ArrayList <String>ar=new ArrayList<String>();
String a="[a-z]([a-z]-[0-9],[a-z]-[0-9])";
Pattern pattern=Pattern.compile(a);
Matcher matcher=pattern.matcher(f);
while(matcher.find()){
if(matcher.find()){
ar.add(matcher.group(0));
}
}
System.out.println(ar.size());
for(int i=0;i<ar.size();i++){
System.out.println(ar.get(i));
}
}
}
但arraylist沒有得到填充。這是爲什麼
+1是'this'與答案接近! – PopoFibo
@PopoFibo然後感謝公平競爭:) – Mena
+1太快.. – gowtham