java:jfc_intf_collection
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| java:jfc_intf_collection [2021/04/05 07:17] – [1ος τρόπος - for()] gthanos | java:jfc_intf_collection [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 16: | Line 16: | ||
| public class StudentCollection { | public class StudentCollection { | ||
| - | |||
| - | private Collection< | ||
| | | ||
| - | public | + | public |
| - | | + | |
| - | | + | |
| + | } | ||
| } | } | ||
| | | ||
| - | public | + | public |
| + | Collection< | ||
| + | students = new LinkedList< | ||
| students.add(new Student(" | students.add(new Student(" | ||
| students.add(new Student(" | students.add(new Student(" | ||
| Line 30: | Line 31: | ||
| students.add(new Student(" | students.add(new Student(" | ||
| students.add(new Student(" | students.add(new Student(" | ||
| - | } | + | iterateCollection(students); |
| - | + | ||
| - | public void iterateList() { | + | |
| - | for(Student st: students) { | + | |
| - | System.out.println(st.toString()); | + | |
| - | } | + | |
| - | } | + | |
| - | + | ||
| - | public static void main(String args[]) { | + | |
| - | StudentCollection stl = new StudentCollection(); | + | |
| - | stl.iterateList(); | + | |
| } | } | ||
| } | } | ||
| Line 47: | Line 38: | ||
| ==== 2ος τρόπος - iterator ==== | ==== 2ος τρόπος - iterator ==== | ||
| - | Μπορείτε να αντικαταστήσετε την '' | + | Μπορείτε να αντικαταστήσετε την '' |
| <code java> | <code java> | ||
| - | public void iterateList() { | + | public |
| Iterator< | Iterator< | ||
| while( it.hasNext() ) { | while( it.hasNext() ) { | ||
java/jfc_intf_collection.1617607068.txt.gz · Last modified: 2021/04/05 06:17 (external edit)
