-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprintList.java
24 lines (20 loc) · 1.09 KB
/
printList.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.*;
public class printList
{
public static void main(String[] Soylu)
{
ArrayList<Integer> list=new ArrayList<>();
for(int i=0;i<10;i++)
list.add(i);
Iterator<Integer> a=list.iterator();
// odaklanalım. Iterator bir sınıf bu sınıftan bir nesne oluşturuyoruz. arraylist objesi ile de iterator() fonksiyonunu çalıştırıyoruz.
// bu metod obje returluyor. bu returlelnen objeyi yeni oluşturduğumuz nesneye atıyoruz :))
// iterator() metodunun Iterotor snıfı ile aynı isimli olmasına aldanmayınız ArrayList 'in objesi çalıştırdığına göre ArrayList sınıfına ait :))
// peki bukadar işi neden yaptık? Iterator sınıfındaki metodlar ile listemizde dolaşacağız :))
while(a.hasNext())
System.out.println(a.next());
//Iterotor sınıfında sıkça kullanacağımız birkaç fonksiyon
//-> hasNext() bir sonrakinde eleman var mı diye kontrol eder. varsa true döndürür.
//-> next() bir sonraki elemanı döndürür.
}
}