P
phi
Hello
We tried the following code using JDK1.6 and tomcat 5.5 (and tomcat 6.0
as well) to enter a "note"-Object into a session.
The list-Variable is an ArrayList and therefore a Java Collection.
The new for-Loop does NOT do the job: the object "note" is always null
in the sesson.
for(Note note : list){
if(note.getNoteId() == noteId.intValue()){
session.setAttribute("note ", note);
break;
}
}
We converted to the old java style loop (using the iterator) and see:
it works!
Iterator iter = list.iterator();
while(iter.hasNext()){
Note n = (Note) iter.next();
if(n.getNoteId() == noteId.intValue()){
session.setAttribute("note", n);
break;
}
}
Any idea what is the differnce between the for(T t: c)-loop and the
Iterator-methods?
We tried the following code using JDK1.6 and tomcat 5.5 (and tomcat 6.0
as well) to enter a "note"-Object into a session.
The list-Variable is an ArrayList and therefore a Java Collection.
The new for-Loop does NOT do the job: the object "note" is always null
in the sesson.
for(Note note : list){
if(note.getNoteId() == noteId.intValue()){
session.setAttribute("note ", note);
break;
}
}
We converted to the old java style loop (using the iterator) and see:
it works!
Iterator iter = list.iterator();
while(iter.hasNext()){
Note n = (Note) iter.next();
if(n.getNoteId() == noteId.intValue()){
session.setAttribute("note", n);
break;
}
}
Any idea what is the differnce between the for(T t: c)-loop and the
Iterator-methods?