Get Synchronized Map example
With this example we are going to demonstrate how to get a synchronized Map. We are using a HashMAp as example, but the same API applies to any type of Map implementation class e.g. TreeMap etc. The...
View ArticleGet Synchronized Set example
In this example we shall show you how to get a Synchronized Set. We are using a HashSet, but the same API applies to any type of Set implementation. The Collections API provides us with methods so as...
View ArticleGet unmodifiable Collection
This is an example of how to get an unmodifiable Collection. The same API applies to any type of Collection implementation classes e.g. HashSet, TreeSet, LinkedHashSet, LinkedList etc. Nevertheless...
View ArticleBinary search List example
With this example we are going to demonstrate how to Binary search a List. We will use the binarySearch(List list, T key) API method of the Collections class. Collections provides static methods that...
View ArticleReplace all elements of List example
In this example we shall show you how to replace all elements of a List. We will use the fill(List list, Object element) API method of the Collections class. Collections provides static methods that...
View ArticleReplace specific element of List example
This is an example of how to replace a specific element of a List. We will use the replaceAll(List list, Object oldVal, Object newVal) API method of the Collections class. The ArrayList is used as a...
View ArticleReverse order of List example
With this example we are going to demonstrate how to reverse the order of a List. This is provided by the reverse(List list) API method of the Collections class. The ArrayList is used as a List...
View ArticleShuffle List elements example
In this example we shall show you how to shuffle a List’s elements. This is provided by the shuffle(List list) API method of the Collections class. The Collections class provides static methods that...
View ArticleSwap List elements example
This is an example of how to swap a List’s elements . We are using the swap(List list, int i, int j) method of the Collections Class. Collections provides static methods that operate on or return...
View ArticleJava Sorted List Example
In this example, I will show how to sort a java.util.List using methods of java.util.Collections class. SimpleSortExample Create a Java class called SimpleSortExample with the following source code....
View Article