Learn Java and Programming through articles, code examples, and tutorials for developers of all levels.
10 Best Practices for Handling Null in Java
How to remove given character from String using Recursion and Iteration in Java? Coding Interview Question
Polymorphism and Open Closed Design Principle Example in Java
Java 8 Stream.filter() example Example with Null and Empty String
How to Create and Extract a ZIP File in Java? Unzip Example Tutorial
Why is Java Considered a Secure Programming Language?
Difference between Queue and Deque in Java? Example Tutorial
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 and this is also a popular Java collection interview question. While he was able to answer the question, he wasn't able to convince interviewer so he asked me how to answer this question. So I am writing this post to share my answer on Queue vs Deque in Java. In the vast world of Java programming, the need to manage data efficiently often leads developers to specialized data structures.
How to find length/size of ArrayList in Java? Example
How to remove all elements of ArrayList in Java - RemoveAll Example
How to loop over a TreeSet in Java with Example
How to Convert Vector to Array in Java? 2 Examples
How to sort a LinkedList in Java? Example Tutorial
10 Example of List in Java
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 pivotal role in managing and manipulating sequences of elements. In the past, I have shared 10 Examples of HashMap in Java and In this article, we'll delve into Java lists, exploring their features and providing ten illustrative examples to deepen your understanding. List are also a popular topic from Java interviews with questions like difference between ArrayList and LinkedList which have been asked to me almost 10 times in past 20 years.
How to Convert a List to a Set in Java with Example
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 can resize itself. The HashMap and ArrayList are two of the most popular classes from the Java Collection framework. Though both are used to store objects they are completely different in their implementation, working, and usage. The main difference between ArrayList and HashMap is that ArrayList is an index-based data structure backed by an array while HashMap is a map data structure that works on hashing to retrieve stored values.
How to sort HashSet in Java? Example
How to declare ArrayList with values in Java? Examples
int[] primes = {2, 3, 5, 7, 11, 13, 17};
or
String[] names = {"john", "Johnny", "Tom", "Harry"};
but unfortunately, ArrayList doesn't support such kind of declaration in Java. But don't worry, there is a workaround to declare an ArrayList with values e.g. String, integers, floats, or doubles by using the Arrays.asList() method, which is nothing but a shortcut to convert an Array to ArrayList.
How to add element at first and last position of linked list in Java? Example Tutorial
Difference between Class and Record in Java?
Hello guys, when it comes to defining data structures in Java, two primary options are at your disposal: records and classes. Each has its unique characteristics and use cases, and understanding the differences between them is crucial for making the right design choices in your Java applications. This has now also become a popular Java interview question and asked to one of my reader recently as well. Java classes have been the cornerstone of object-oriented programming for years, offering full customization and flexibility. They allow you to define complex objects with custom behavior, encapsulation, and fine-grained control over state changes.
Difference between HashMap and LinkedHashMap 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 the insertion order of keys, the order in which keys are inserted into LinkedHashMap. On the other hand, HashMap doesn't maintain any order or keys, or values. In terms of performance, there is not much difference between HashMap and LinkedHashMap but yes LinkedHashMap has more memory footprint than HashMap to maintain doubly LinkedList which it uses to keep track of the insertion order of keys.