Github Gists
HomeGithub Gists
Concatenate Strings Using StringBuffer.append()
In addition to String, Java has the java.lang.StringBuffer and java.lang.StringBuilder classes. These can also be used to concatenate Strings. The advantage of these classes is that both these classes are mutable, so using them does not result in...
Concatenate Strings Using String.concat()
The String class has a method called concat. It accepts as parameter a String value and concatenates it with the current String. The following code demonstrates this: As before, this code creates string1 and string2. It then invokes the...
Concatenate Strings Using Plus Operator
In Java, a String is a sequence of characters. There are often programming situations where you will need to concatenate Strings. There are several ways in which you can achieve this. The + operator is also known as the...
Remove Duplicates from List Using Stream
Java 8 has added the Stream API that helps to easily perform bulk operations on Collections. A new method called stream() method has been added to all the collection interfaces that returns a Stream corresponding to the underlying collection....
Convert List to Array Using ToArray With Param
There is an overloaded version of the toArray method. This accepts an array as a parameter and returns a result array that is of the same data type as the input array. So basically, this toArray method can be used to...
Remove Duplicates from List Using Set.addAll
The Set interface has a method called addAll. This accepts a 'Collection' as the parameter. So if you invoke this method by passing the 'List', the duplicates will be eliminated. The following code snippet demonstrates this method. Here, a new...
Convert List to Array Using ToArray Without Param
Java provides a toArray method on the 'List' interface. This can be used to convert a 'List' to an array. Since there are are two overloaded versions, one of these method is explained below. This toArray method does not accept...
Remove Duplicates from List Using LinkedHashSet
Another implementation of the Set interface is LinkedHashSet. LinkedHashSet maintains the order of elements and helps to overcome the HashSet limitation. The following code demonstrates this: This code is quite similar to the one seen earlier, except that it uses...
Convert List to Array Using Stream with Param
There is an overloaded version of the Stream.toArray method which can be used to return a result array that is of the same data type as the input array. The following code demonstrates this: Firstly, the 'stream()' method is invoked...
Remove Duplicates from List Using HashSet
The Set is also an interface in the 'Java Collection' framework. Unlike a List, a Set does not allow duplicates. Hence you can use a Set to eliminate the duplicates in a List. There are several ways in...
Convert List to Array Using Stream without Param
Java 8 has added the Stream API that helps to easily perform bulk operations on Collections. A new method called stream() has been added to all the collection interfaces that returns a Stream corresponding to the underlying collection. There is...
Remove Duplicates from List Using For-Loop
The simplest way to remove duplicates from a 'List' is to use a for-loop. The following code snippet demonstrates this method. First, the code creates a new ArrayList to store the output, i.e. a List without duplicates. A for-loop is...
Convert List to Array Using For-Loop
The simplest way to convert a List to an array is to use a for-loop. The following code snippet demonstrates this method. First, the code creates an Array based on the number of elements in the input List. A for-loop...
Github Gists
POPULAR | TAGS
LATEST POSTS
Basic PowerShell Commands That You Should Know
One of the key benefits of PowerShell is its object-oriented nature. Instead of working with text-based output like traditional command-line interfaces, PowerShell returns objects...
How To Always Open Files in New Tab in VSCode
The VSCode has rocketed its way to one of the top development IDEs due to its fresh look, usability, tons of feature sets, and...
How To Install Oh-My-Posh On Windows PowerShell
Oh-My-Posh is a powerful custom prompt engine for any shell that has the ability to adjust the prompt string with a function or variable....
TOP | CATEGORIES
Most Commented
Interpreted Vs Compiled Languages
This is based on an excerpt from one of my favourite literature on VBScript and in fact,...