HashSet in Java is a collection which implements Set interface and backed by an HashMap. Since HashSet uses HashMap internally it provides constant time performance for operations like add, remove, contains and size give HashMap has distributed elements properly among the buckets. Java HashSet does not guarantee any insertion orders of the set but it allows null elements. HashSet can be used in place of ArrayList to store the object if you require no duplicate and don't care about insertion order. Iterator of HashSet is fail-fast and throws ConcurrentModificationException if HashSet instance is modified concurrently during iteration by using any method other than remove() method of iterator class.If you want to keep insertion order by using HashSet than consider using LinkedHashSet. It is also a very important part of any Java collection interview, In short correct understanding of HashSet is must for any Java developer.
Tampilkan postingan dengan label examples. Tampilkan semua postingan
Tampilkan postingan dengan label examples. Tampilkan semua postingan
HashSet in Java – 10 Examples Programs Tutorial
Senin, 03 Februari 2014
Read more »
Diposting oleh
pebel
di
11.30
0
komentar
Kirimkan Ini lewat Email
BlogThis!
Bagikan ke X
Berbagi ke Facebook
What is Race Condition in multithreading – 2 Examples in Java
Sabtu, 01 Februari 2014
Race condition in Java is a type of concurrency bug or issue which is introduced in your program because parallel execution of your program by multiple threads at same time, Since Java is a multi-threaded programming language hence risk of Race condition is higher in Java which demands clear understanding of what causes a race condition and how to avoid that. Anyway Race conditions are just one of hazards or risk presented by use of multi-threading in Java just like deadlock in Java. Race conditions occurs when two thread operate on same object without proper synchronization and there operation interleaves on each other. Classical example of Race condition is incrementing a counter since increment is not an atomic operation and can be further divided into three steps like read, update and write. if two threads tries to increment count at same time and if they read same value because of interleaving of read operation of one thread to update operation of another thread, one count will be lost when one thread overwrite increment done by other thread. atomic operations are not subject to race conditions because those operation cannot be interleaved. This is also a popular multi-threading interview questions during core java interviews. In this article we will see how to find race condition in Java and two sample code patterns which often causes race conditions in Java.
Diposting oleh
pebel
di
22.00
0
komentar
Kirimkan Ini lewat Email
BlogThis!
Bagikan ke X
Berbagi ke Facebook
Langganan:
Postingan (Atom)