私は、テキストファイルからテキストを読み込んで、単語カウントを生成し、ファイル内で使用されている各単語の出現をリストするプログラムを作成する作業をします。Javaのハイフンで文字列を爆発させる方法は?
私はこの文字列 "hello-funny-world"を3つの別個の文字列として見て、それを私の配列リストに格納したいと思っています。これは、単語数から句読点を取り除くことができました。私はこれまでのところ、コードのこの部分、私は問題を抱えて、私はちょうど1つの文字列と見られて「ハロー面白い世界」を取得してい:
while (reader.hasNext()){
String nextword2 = reader.next();
String nextWord3 = nextword2.replaceAll("[^a-zA-Z0-9'-]", "");
String nextWord = nextWord3.replace("-", " ");
int apcount = 0;
for (int i = 0; i < nextWord.length(); i++){
if (nextWord.charAt(i)== 39){
apcount++;
}
}
int i = nextWord.length() - apcount;
if (wordlist.contains(nextWord)){
int index = wordlist.indexOf(nextWord);
count.set(index, count.get(index) + 1);
}
else{
wordlist.add(nextWord);
count.add(1);
if (i/2 * 2 == i){
wordlisteven.add(nextWord);
}
else{
wordlistodd.add(nextWord);
}
}
'String#split()'を使うだけで、配列 – TheLostMind