Hello guys, if you want to learn ArrayList in-depth and looking for a complete guide on ArrayList then you have come to the right place. Earlier, I have shared the best Java collection courses and in this article, I am going to s…
Read more
Hello guys, the Comparator class is used to provide code or logic for comparing objects in Java, while sorting a list of objects or a collection of objects. It's close cousin of Comparable which provides natural order sortin…
Read more
Hello guys, if you have a List of numbers and you want to shuff it but don't know how then you have come to the right place. Shuffling is an important technique which is used quite a lot on coding games like number guessing …
Read more
HashSet and HashMap in Java Hello friends, if you have given Java developer interview then there is good chance that you may have come across questions like Difference between HashSet vs HashMap or HashSet vs TreeSet etc. In thi…
Read more
Hello Java programmers, sorting ArrayList in Java is not difficult; there are multiple ways to sort a given ArrayList in Java. For example you can use the Collections.sort() method to sort ArrayList in ascending and descendi…
Read more
You can use the set() method of java.util.ArrayList class to replace an existing element of ArrayList in Java. The set(int index, E element) method takes two parameters, the first is the index of an element you want to replace…
Read more
ArrayList vs HashSet Java The main difference between ArrayList and HashSet is that one is a List implementation while the other is a Set implementation. It means all the differences between a List data structure and a S…
Read more
Hello guys, today I am going to share another interesting question from Java interview, what is difference between Queue and Deque in Java. This question was asked to one of my reader in a recent interview with JP Morgan Mumbai a…
Read more
You can use the size() method of java.util.ArrayList to find the length or size of ArrayList in Java. The size() method returns an integer equal to a number of elements present in the array list. It's different than the l…
Read more
There are two ways to remove all elements of an ArrayList in Java, either by using clear() or by using the removeAll() method. Both methods are defined in the java.util.List and java.util.Collection interface, hence they a…
Read more
In our earlier articles, we have learned how to loop over ArrayList in Java and you can use the same logic to loop over a TreeSet . You can use both, enhanced for loop and Iterator to traverse over TreeSet in Java. Though wort…
Read more
In the last article, we have learned how to convert a LinkedList to an array in Java , and in today's tutorial, you will learn how to convert a Vector to an array in Java . There is a similarity between Vector and LinkedList…
Read more
Since LinkedList implements the java.util.List interface, you can sort the LinkedList by using the Collections.sort() method, just like you sort an ArrayList . Since the LinkedList class implements the linked list data struct…
Read more
Hello guys, Java, as a versatile and widely used programming language, offers a plethora of data structures to developers. One of them is List which is also fundamental component in Java's collection framework, play a pivota…
Read more
How to convert a List to Set in Java Many times we need to convert one collection to another like converting a List to a Set . It's also an easy way to copy contents from one collection to other in Java, like from List to …
Read more
Difference between ArrayList and HashMap in Java One of the most critical differences between the HashMap and ArrayList class is that the former is the implementation of the hash table while the latter is a dynamic array that c…
Read more
Somebody asked me recently, how do you sort a HashSet? For lists, we use the Collections.sort(List) method, but there is nothing for Set. If I have a HashSet then how would I go about sorting it? The answer is you cannot sort a…
Read more
Sometimes you want to create an ArrayList with values , just like you initialize t at the time of declaration, as shown below: int[] primes = {2, 3, 5, 7, 11, 13, 17}; or String[] names = {"john", "Johnny"…
Read more
LinkedList class in java.util package provides the addFirst() method to add an element at the start of the linked list (also known as head) and addLast() method to add an element at the end of the linked list, also known as …
Read more
Difference between LinkedHashMap and HashMap in Java HashMap and LinkedHashMap are two of the most commonly used Map implementation in Java. The main difference between HashMap and LinkedHashMap is that LinkedHashMap maintains t…
Read more