假设字符串是:
The/at Fulton/np-tl County/nn-tl Grand/jj-tl
如何删除后面/和下面的字符如下所示
The Fulton County Grand
我有一个for循环方法的问题,只有循环1次是什么问题?在数组中没有任何问题,它能够打印我想要的值.
这是我的代码:
public static void main(String[] args){
String s = "Apple0, Apple1, Apple2, Apple3, Apple4";
String[] word = s.split(",");
StringBuffer str = new StringBuffer();
Integer total = 0;
for (int y = 0; y < word.length; y++){
if(word[y].toString().equals("Apple2") ){
total++;
//str.append(word[y].toString());
}else if(word[y].toString().equals("Apple3") ){
total++;
//str.append(word[y].toString());
}else if(word[y].toString().equals("Apple4") ){
total++;
//str.append(word[y].toString());
}
else if(word[y].toString().equals("Apple1") ){
total++;
//str.append(word[y].toString());
}
}
System.out.println( word[0] + word[1] + word[2] + word[3] + word[4] + word.length);
System.out.println(str + "hihi" + total);
}
Run Code Online (Sandbox Code Playgroud) 我怎么可以把类似的句子"He and his brother playing football."成几部分一样"He and","and his","his brother","brother playing"和"playing football".是否可以通过使用Java来实现?
假设文本文件包含:
He is a boy .
She is sick .
Ali is playing .
We are eating .
The dog is barking .
He and his brother are running .
Run Code Online (Sandbox Code Playgroud)
如何将所有句子放入数组列表格式:
He is
is a
a boy
boy .
She is
is sick
sick .
Run Code Online (Sandbox Code Playgroud)
等等.
我使用数组列表来避免继续读取文本文件来执行某些任务是否可能?或者我需要使用vector来做到这一点?