Home » Tag Archives: Collections

Tag Archives: Collections

Java Arrays Sort decoded

java-logo

Sorting is one the first algorithm that we learn in computer science. Sorting is such an interesting area that it has around 20+ algorithm and it is always difficult to decided which one is best. Sorting algorithm efficiency is measured in terms of time taken & space required. Some time bubble sort is best because it has no space requirement and for ...

Read More »

9 differences between Array and ArrayList in Java

java-logo

Both array and ArrayList are two important data structures in Java and are frequently used in Java programs. Even though ArrayList is internally backed by an array, knowing the difference between an array and an ArrayList in Java is critical for becoming a good Java developer. If you know the similarity and differences, you can judiciously decide when to use ...

Read More »

10 Examples of using ArrayList in Java – Tutorial

java-logo

ArrayList in Java is the most frequently used collection class after HashMap. Java ArrayList represents an automatic re-sizeable array and used in place of array. Since we can not modify the size of an array after creating it, we prefer to use ArrayList in Java which re-size itself automatically once it gets full. ArrayList in Java implements List interface and allow ...

Read More »

Leaner Java Collections with FastUtil

java-logo

In response to my recent post Discovering a Trove of Java Primitives Collection Handling on the GNU Trove library, TheAlchemist pointed out some advantages of fastutil over trove: “I much prefer fastutil (http://fastutil.di.unimi.it/), because it’s still in active development, has more features, supports large sizes (> 2^32), and has better documentation.” Attila-Mihaly Balazs has seconded this: “I second @TheAlchemist’s recommendation ...

Read More »

An introduction to optimising a hashing strategy

java-logo

Overview The strategy that’s used for hashing keys, can have a direct impact on the performance of a hashed collections such as a HashMap or HashSet. The built-in hashing functions are designed to be generic and work well in a wide range of use cases. Can we do better, especially if you have a good idea of the use case? ...

Read More »

Optional in collections

java-logo

Sometime it is argued that the type Optional is worth being used in collections. It allegedly solves the problem of e.g.: HashMap that returns null in case there is no mapping for a key as well as when the value null is mapped to the key. If you use a Map<Optional<Something>> then you can clearly separate a missing mapping and ...

Read More »

Consuming java.util.concurrent.BlockingQueue as rx.Observable

java-logo

Classical producer-consumer pattern is relatively simple in Java since we have java.util.concurrent.BlockingQueue. To avoid busy waiting and error-prone manual locking we simply take advantage of put() and take(). They both block if queue is full or empty respectively. All we need is a bunch of threads sharing reference to the same queue: some producing and others consuming. And of course ...

Read More »

Transforming Collections

java-logo

Did you ever want to substitute the equals and hashCode methods a HashSet or HashMap uses? Or have a List of some element type masquerade as a List of a related type? Transforming collections make that possible and this post will show how. Overview Transforming collections are a feature of LibFX 0.3.0, which will be released any day now. This ...

Read More »

How to Use Java 8 Streams to Swiftly Replace Elements in a List

java-logo

Imagine you have a list of items: List<String> books = Arrays.asList( "The Holy Cow: The Bovine Testament", "True Hip Hop", "Truth and Existence", "The Big Book of Green Design" ); (Don’t judge me. Books from this random book generator) Now you’d like to create a new list where the third item only is replaced by some new value: List<String> books ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns