Custom ArrayList in Java26 Mar 2025 | 5 min read In Java, array and ArrayList are the well-known data structures. An array is a basic functionality provided by Java, whereas ArrayList is a class of Java Collections framework. It belongs to java.util package. The limitation of the ArrayList is that it allows us to store data of the same data type. To overcome this problem, we can customize the ArrayList and can store data of different primitive types. In this section, we are going to learn custom ArrayList in Java and how to implement custom ArrayList in Java. Before moving to the custom ArrayList, let's have a look at ArrayList in Java. Java ArrayList ClassIn Java, ArrayList is a class of Java Collections framework. It implements List<E>, Collection<E>, Iterable<E>, Cloneable, Serializable, and RandomAccess interfaces. It extends the AbstractList<E> class. It uses a dynamic array for storing the elements. We can create an instance of ArrayList by using the following statement: ArrayList is internally backed by the array in Java. The resize operation in ArrayList slows down the performance as it involves a new array and copying content from an old array to a new array. It calls the native implemented method System.arraycopy(sec, srcPos, dest, destPos, length). We cannot store primitive type in ArrayList. So, it stores only objects. It automatically converts primitive type to object. For example, we have created an ArrayList object: The JVM converts it into Integer object through auto-boxing. Custom ArrayList in JavaA list that contains more than one type of data (elements) is known as custom ArrayList. It is based on user requirements. In the custom ArrayList, the data is provided by the custom inner class that is formed by a combination of various primitive object datatypes. Consider a situation, if we want to take input of product detail. The detail includes pid, pname, pavailability, pprice, prating. Typically to input these attributes in the ArrayList, we need to create a separate ArrayList for each attribute, as follows: The above process is lengthy and takes lots of time to input the elements. It uses separate ArrayList to store each attribute. To overcome the problem, we use custom ArrayList. It stores more than one data type in a single ArrayList. For example, consider the following figure: ![]() In the above figure, we have created an ArrayList. In all the indices of ArrayList, we have stored different data such as accno, name, and interest. Implementation of Custom ArrayList in JavaTo implement the custom ArrayList in Java, follow the steps given below:
Let's follow the above steps and implement the custom ArrayList. Example of Custom ArrayListCustomArrayListExample.java Output: ![]() |
Caching is the process of storing and accessing data from memory (cache memory). The main feature of caching is to reduce the time to access specific data. Caching aims at storing data that can be helpful in the future. The reason for caching is that accessing...
6 min read
? Sometimes, we are required to represent data in tabular format or in table form, especially when we are dealing with the database. In this section, we will create Java programs that print data on the console in tabular or table format. There are many ways to print...
4 min read
The interface used by the Java programming language is by the name Java Naming and Directory Interface (JNDI). It is an API (application programming interface) that communicates with servers and uses naming conventions to get files from databases. A word or a single phrase might serve...
6 min read
A common problem when dealing with linked lists in programming is determining whether two linked lists intersect. If intersect, find the node where the linked intersect. This scenario arises when two linked lists share a common set of nodes at their end, forming a Y-shaped structure....
6 min read
In the vast landscape of software development, the ability to execute multiple tasks concurrently is paramount. In the Java programming language, multithreading is the avenue through which developers can achieve this concurrency. However, as threads vie for the CPU's attention, a fascinating and critical process comes...
4 min read
The SimpleTimeZone class contains the setStartYear() method is used to specify the year when daylight saving time begins. Syntax: public void setStartYear(int year) Parameters: The single parameter year, which indicates the year when daylight saving time begins, is accepted by the function. Return Value: No value is...
2 min read
In Java, to find the square root of a number is very easy if we are using the pre-defined method. Java Math class provides sqrt() method to find the square root of a number. In this section, we will create a Java program to find the...
3 min read
Programmers may design effective and responsive programs with the help of Java's robust features, which make it a versatile and popular language. Multithreading and multiprogramming are two essential ideas in Java that are connected to concurrent execution. Although both include carrying out several activities at once,...
4 min read
In this section, we will learn what is a narcissistic number and also create Java programs to check if the given number is a narcissistic number or not. The narcissistic number program is frequently asked in Java coding interviews and academics. Narcissistic Number A narcissistic number is a...
3 min read
The java.time.format.DecimalStyle class is the getDecimalSeparator() method. The character that is used to indicate the decimal separator for the Locale of this DecimalStyle in Java is obtained using the DecimalStyle class. The procedure returns the character for that locale's decimal separator. Syntax: public char getDecimalSeparator() Parameter: No parameter is...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India