List vs Set vs Map in Java

List, Set, and Map interfaces are very important part of collection framework. List and Set implements Collection interface but Map does not. Let us discuss all with examples and differences. Collection Hierarchy: Map Hierarchy: List A List in java extends the collection interface and represent an sequenced or ordered group of elements. It can contain … Read more

Iterator vs ListIterator vs Enumeration in Java

All Iterator, ListIterator, and Enumeration represents cursors in java which are used to iterate over collection elements. But they have some differences also. Let us discuss each with example, when to use which, and differences. Iterator Iterator interface present in java.util package. It is used to read or remove the collection elements by iterating over … Read more

Arraylist vs LinkedList vs Vector in java

All ArrayList LinkedList, and Vectors implement the List interface. Both (ArrayList and Vectors) use dynamically resizable arrays as their internal data structure. Whereas both ArrayList and Linked List are non synchronized. But they have several differences also, let us discuss ArrayList, LinkedList and Vectors in details with examples and differences. Collection Interface   ArrayList: ArrayList … Read more

Can we make the user thread as daemon thread if thread is started?

No, if we make the user thread as daemon thread if thread is started, it will throw IllegalThreadStateException. Java interview questions on multithreading What is multithreading? Difference between process and thread in java? What is thread in java? What is the difference between preemptive scheduling and time slicing? What is join method in java? What … Read more

Thread Java

Multithreading: Multithreading refers to a type of multitasking based upon threads. Context switching in case of multi-threading is done in-between threads instead of processes. Thread: A thread is used to execute multiple activities or tasks with-in a single process. It refers to a lightweight process. Thread uses process’s memory area i.e. execution environment. Multiple threads … Read more

Process vs Thread java

Multiprocessing: Multiprocessing represents a type of multitasking which is based upon processes. Context switching in Multiprocessing, is done in-between processes. For example: Listening music, downloading file, Typing in notepad etc from internet at the same time. You can clearly identify that all applications like music software, notepad etc are independent. Multiprocessing is handled at OS … Read more

Jagged arrays in java

Jagged arrays are also known as ragged arrays. They are the arrays containing arrays of different length. Consider the below example in which each row consists of different number of elements. First row contains 4 elements, second row contains 2 elements and third row contains 3 elements. Example package com.w3spoint;   import java.util.Arrays;   public … Read more

difference between array and arraylist in java?

Array ArrayList Array objects are of fixed length. ArrayList objects are of variable length. Array does not support generics. ArrayList supports generics. Array can store both primitive types as well as reference types. ArrayList can store only reference types. Length of the Array is provided by the length variable. Length of the ArrayList is provided … Read more

Anonymous Array in java

An array without any name is anonymous array in java. They are mainly created for one time use only. Note: Anonymous arrays can be passed as an argument of a method. Syntax: Anonymous Int Array new int[] { 15, 25, 23, 45, 34}; Syntax: Anonymous Char Array new char[] {‘a’, ‘b’, ‘c’, ‘d’); Syntax: Anonymous … Read more

Change array size in java

No, we cannot change array size in java after defining. Note: The only way to change the array size is to create a new array and then populate or copy the values of existing array into new array or we can use ArrayList instead of array. Example: Custom Approach public class Main { public static … Read more