テキストの文字列と、文字列で検索する必要がある特定の単語があります。文字列内で次に出現する単語を見つけたら、その単語の直後にある文字をどうにかして見つける必要があります。スキャナーを使用しようとしましたが、 nextChar() メソッドが含まれていません。そのようなものが、私がやろうとしていることの目的に役立ちます。他に何を試すことができますか?ここに私が持っているコードがありますが、それは私がやりたいことをしません。
public void storeChar(String str) //used to get the char after the seed and store it in the arraylist of chars
{
Scanner sc = new Scanner(str);
seed = wrdSd.getSeed();
while(sc.hasNext()) //while there are words left to read
{
String next = sc.next();
if(next.equals(seed)) //if the next word of the scanner = the seed
{
ch = sc.next().charAt(0); //gets char at index 0 of the next word
singleChar.add(ch); //adds the char to the char arraylist
}
}
sc.close();
}
前もって感謝します!