Java 增强for循环

Java 增强for循环,java,for-loop,foreach,Java,For Loop,Foreach,你能把这个增强的for循环转换成普通的吗? for(字符串句子:notes.split(“*\”) 当数据类型为整数时,我喜欢增强型和普通型for循环。但如果它是一根弦,我就糊涂了。多谢各位 普通循环- String[] splitResult=notes.split(" *\."); for (String sentence : splitResult) String[] strArray = notes.split(" *\."); String sentence = null;

你能把这个增强的for循环转换成普通的吗?
for(字符串句子:notes.split(“*\”)


当数据类型为整数时,我喜欢增强型和普通型for循环。但如果它是一根弦,我就糊涂了。多谢各位

普通循环-

String[] splitResult=notes.split(" *\.");
for (String sentence : splitResult)
String[] strArray = notes.split(" *\.");
String sentence = null;
  for(int i=0 ;i <strArray.length ; i++){
    sentence = strArray[i];
   }
String[]strArray=notes.split(“*\”);
字符串语句=null;
对于(int i=0;i
String[]句=notes.split(“*\”);
字符串语句=null;
int-sentencesLength=句子长度;

for(int i=0;i
split
返回
字符串[]

String[] array=notes.split(" *\.");
for(int i=0;i<array.length();i++) {

    System.out.println(array[i]);
}
String[]数组=notes.split(“*\”);

对于(int i=0;i你可以有这样的结果:

String[] splitString = notes.split(" *\."));
for (int i = 0; i < splitString.length; i++)
{
    //...
}
String[]数组=notes.split(“*\”);
串句;
for(int i=0;i
您应该看看


我猜正则表达式本身是错误的。编译器会说

非法转义字符

如果

“*\”

是正则表达式。所以我假设您正试图通过

(一个点)

作为分隔符。在这种情况下,代码如下

String[] splittedNotes = notes.split("[.]");
for (int index = 0; index < splittedNotes.length; index++) {
   String sentence = splittedNotes[index];
}
String[]splittedNotes=notes.split([.]);
对于(int index=0;index

礼貌地说,你本可以自己尝试并得到这个。干杯。

这是我们的书中写的,我很好奇它与普通的对应物是什么。
句子=拆分的注释[I++]
?如果
i
实际上没有被使用,那么在循环中不需要它。您可以将
i++
部分拉入
的第三部分,以便
;句子=…,i++
而不是
句子=拆分的注释[i],i++
您可以始终使用
句子=拆分的注释[i++]
)正在使用基本
i
。他只需记下每个拆分的笔记的字符串。但是你的代码更精简!隐马尔可夫模型。。第二个建议:在第一次迭代中,
句不是第一句,而是
”。在上一次迭代中,您会得到一个
ArrayIndexOutOfBoundsException
。酷!非常感谢你,Priyank Doshi!最佳实践:添加
n
(不要在每个循环中求值):
for(int i=0,n=句子长度;i
for(String str : splitString)
{
    //...
}
String [] array = notes.split(" *\."));
String sentence;
for(int i = 0; i < array.length; i ++) {
sentence = array[i];
}
String[] splitted_notes = notes.split(" *\. ");
for (int i=0; i < splitted_notes.length; i++) {
  // Code Here with splitted_notes[i]
}
ArrayList<String> splitted_notes = new ArrayList<>(Arrays.asList(notes.split(";")));
for(Iterator<String> i = splitted_notes.iterator(); i.hasNext(); ) {
  String sentence = i.next();
  // Code Here with sentence
}
String[] splittedNotes = notes.split("[.]");
for (int index = 0; index < splittedNotes.length; index++) {
   String sentence = splittedNotes[index];
}