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 [2020/03/12 17:03] – [Εργασίες με πολλαπλές εγγραφές] gthanos | java:jfc_intf_collection [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 5: | Line 5: | ||
===== Διάτρεξη ενός Collection ===== | ===== Διάτρεξη ενός Collection ===== | ||
- | ==== 1ος τρόπος - for() ==== | + | To interface [[https:// |
+ | - μέσω For-Each Loop. | ||
+ | - με τη βοήθεια ενός [[https:// | ||
+ | |||
+ | ==== 1ος τρόπος - For-Each Loop ==== | ||
<code java StudentCollection.java> | <code java StudentCollection.java> | ||
Line 12: | 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 26: | 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 43: | 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.1584032619.txt.gz · Last modified: 2020/03/12 17:03 (external edit)