What Is Deviation Betwixt Enumeration Together With Iterator Inward Java?

What Is Deviation Betwixt Enumeration Together With Iterator Inward Java? - Hallo sahabat BEST LEARNING JAVA, Pada Artikel yang anda baca kali ini dengan judul What Is Deviation Betwixt Enumeration Together With Iterator Inward Java?, kami telah mempersiapkan artikel ini dengan baik untuk anda baca dan ambil informasi didalamnya. mudah-mudahan isi postingan Artikel collections interview questions, Artikel core java, Artikel core java interview question, Artikel java collection tutorial, yang kami tulis ini dapat anda pahami. baiklah, selamat membaca.

Judul : What Is Deviation Betwixt Enumeration Together With Iterator Inward Java?
link : What Is Deviation Betwixt Enumeration Together With Iterator Inward Java?

Baca juga


What Is Deviation Betwixt Enumeration Together With Iterator Inward Java?

Though both Iterator too Enumeration allows you lot to traverse over elements of Collections inward Java, at that topographic point is only about pregnant departure betwixt them e.g. Iterator besides allows you lot to take elements from collection during traversal but Enumeration doesn't allow that, it doesn't got the remove() method. Enumeration is besides a legacy flat too non all Collection supports it e.g. Vector supports Enumeration but ArrayList doesn't. On the other mitt Iterator is the measure flat for iteration too traversal. By the way,  what is departure betwixt Enumeration too Iterator inward Java?  This inquiry is from early on ages of  Java interview , I possess got non seen this inquiry on recent interviews but it was quite mutual during 2000 to 2007 period, immediately days questions similar implementation of HashMap or ConcurrentHashMap etc has taken its place, even too therefore its real of import to know the key difference betwixt Iterator too Enumeration. Some fourth dimension its besides asked every bit Iterator vs Enumeration or Enumeration vs Iterator which is same. Important betoken to banking enterprise complaint is that both Iterator too Enumeration provides agency to traverse or navigate through entire collection inward Java.

Iterator vs Enumeration

 Though both Iterator too Enumeration allows you lot to traverse over elements of Collections  What is departure betwixt Enumeration too Iterator inward Java?Between Enumeration too Iterator, Enumeration is older too its at that topographic point from JDK1.0, acre iterator was introduced later. Iterator tin dismiss last used alongside ArrayList, HashSet and other collection classes.  Another similarity betwixt Iterator too Enumeration inward Java is that  functionality of Enumeration interface is duplicated yesteryear the Iterator interface.


Only major departure betwixt Enumeration too iterator is Iterator has a remove() method acre Enumeration doesn't. Enumeration acts every bit Read-only interface, because it has the methods exclusively to traverse too fetch the objects, where every bit yesteryear using Iterator nosotros tin dismiss manipulate the objects similar adding too removing the objects from collection e.g. Arraylist.

Also Iterator is to a greater extent than secure too security every bit compared to Enumeration because it  does non allow other thread to alter the collection object acre only about thread is iterating over it too throws ConcurrentModificationException. This is yesteryear far almost of import fact for me for deciding betwixt Iterator vs Enumeration inward Java.

In Summary both Enumeration too Iterator volition hand successive elements, but Iterator is novel too improved version where method names are shorter, too has novel method called remove. Here is a brusque comparison:

Enumeration
hasMoreElement()
nextElement()
N/A


Iterator
hasNext()
next()
remove()

So Enumeration is used when e'er nosotros desire to brand Collection objects every bit Read-only.

Further Learning
Java In-Depth: Become a Complete Java Engineer
Why String is immutable inward Java



Demikianlah Artikel What Is Deviation Betwixt Enumeration Together With Iterator Inward Java?

Sekianlah artikel What Is Deviation Betwixt Enumeration Together With Iterator Inward Java? kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.

Anda sekarang membaca artikel What Is Deviation Betwixt Enumeration Together With Iterator Inward Java? dengan alamat link https://bestlearningjava.blogspot.com/2020/04/what-is-deviation-betwixt-enumeration.html

Belum ada Komentar untuk "What Is Deviation Betwixt Enumeration Together With Iterator Inward Java?"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel