What Is Dynamic Array In Java? | How Do They Work? - Edureka

  1. Blog
  2. What Is Dynamic Array In Java?
Java/J2EE and SOA (344 Blogs) Become a Certified Professional AWS Global Infrastructure
Introduction to Java
  • What Is Java? A Beginner's Guide to Java and Its Evolution
  • Why Java is a Popular Programming Language?
  • Top 10 Reasons Why You Should Learn Java
  • Why Java is a Secure language?
  • What are the different Applications of Java?
  • Java for Android: Know the importance of Java in Android
  • What is the basic Structure of a Java Program?
  • What is the difference between C, C++ and Java?
  • Java 9 Features and Improvements
  • Top 10 Java Frameworks You Should Know
  • Netbeans Tutorial: What is NetBeans IDE and how to get started?
Environment Setup
  • How To Set Path in Java?
  • How to Write Hello World Program in Java?
  • How to Compile and Run your first Java Program?
  • Learn How To Use Java Command Line Arguments With Examples
Control Statements
  • What is for loop in java and how to implement it?
  • What is a While Loop in Java and how to use it?
  • What is for-each loop in Java?
  • What is a Do while loop in Java and how to use it?
  • What is a Switch Case In Java?
Java Core Concepts
  • Java Tutorial For Beginners – Java Programming Made Easy!
  • What are the components of Java Architecture?
  • What are Comments in Java? – Know its Types
  • What are Java Keywords and reserved words?
  • What is a Constructor in Java?
  • What is the use of Destructor in Java?
  • Know About Parameterized Constructor In Java With Examples
  • What are Operators in Java and its Types?
  • What Are Methods In Java? Know Java Methods From Scratch
  • What is Conditional Operator in Java and how to write it?
  • What is a Constant in Java and how to declare it?
  • What is JIT in Java? – Understanding Java Fundamentals
  • What You Should Know About Java Virtual Machine?
  • What is the role for a ClassLoader in Java?
  • What is an Interpreter in Java?
  • What is Bytecode in Java and how it works?
  • What is a Scanner Class in Java?
  • What is the Default Value of Char in Java?
  • this Keyword In Java – All You Need To Know
  • What is Protected in Java and How to Implement it?
  • What is a Static Keyword in Java?
  • What is an Array Class in Java and How to Implement it?
  • What is Ternary Operator in Java and how can you use it?
  • What is Modulus in Java and how does it work?
  • What is the difference between Method Overloading And Overriding?
  • Instance variable In Java: All you need to know
  • Know All About the Various Data Types in Java
  • What is Typecasting in Java and how does it work?
  • How to Create a File in Java? – File Handling Concepts
  • File Handling in Java – How To Work With Java Files?
  • What is a Comparator Interface in Java?
  • Comparable in Java: All you need to know about Comparable & Comparator interfaces
  • What is Iterator in Java and How to use it?
  • Java Exception Handling – A Complete Reference to Java Exceptions
  • All You Need to Know About Final, Finally and Finalize in Java
  • How To Implement Volatile Keyword in Java?
  • Garbage Collection in Java: All you need to know
  • What is Math Class in Java and How to use it?
  • What is a Java Thread Pool and why is it used?
  • Synchronization in Java: What, How and Why?
  • Top Data Structures & Algorithms in Java That You Need to Know
  • Java EnumSet: How to use EnumSet in Java?
  • How to Generate Random Numbers using Random Class in Java?
  • Generics in Java – A Beginners Guide to Generics Fundamentals
  • What is Enumeration in Java? A Beginners Guide
  • Transient in Java : What, Why & How it works?
  • What is Wait and Notify in Java?
  • Swing In Java : Know How To Create GUI With Examples
  • Java AWT Tutorial – One Stop Solution for Beginners
  • Java Applet Tutorial – Know How to Create Applets in Java
  • How To Implement Static Block In Java?
  • What is Power function in Java? – Know its uses
  • Java Array Tutorial – Single & Multi Dimensional Arrays In Java
  • Access Modifiers in Java: All you need to know
  • What is Aggregation in Java and why do you need it?
  • How to Convert Int to String in Java?
  • What Is A Virtual Function In Java?
  • Java Regex – What are Regular Expressions and How to Use it?
  • What is PrintWriter in Java and how does it work?
  • All You Need To Know About Wrapper Class In Java : Autoboxing And Unboxing
  • How to get Date and Time in Java?
  • What is Trim method in Java and How to Implement it?
  • How do you exit a function in Java?
  • What is AutoBoxing and unboxing in Java?
  • What is Factory Method in Java and how to use it?
  • Threads in Java: Know Creating Threads and Multithreading in Java
  • Join method in Java: How to join threads?
  • What is EJB in Java and How to Implement it?
  • What is Dictionary in Java and How to Create it?
  • Daemon Thread in Java: Know what are it's methods
  • How To Implement Inner Class In Java?
  • What is Stack Class in Java and how to use it?
Java Strings
  • What is the concept of String Pool in java?
  • Java String – String Functions In Java With Examples
  • Substring in Java: Learn how to use substring() Method
  • What are Immutable String in Java and how to use them?
  • What is the difference between Mutable and Immutable In Java?
  • BufferedReader in Java : How To Read Text From Input Stream
  • What are the differences between String, StringBuffer and StringBuilder?
  • Split Method in Java: How to Split a String in Java?
  • Know How to Reverse A String In Java – A Beginners Guide
  • What is Coupling in Java and its different types?
  • Everything You Need to Know About Loose Coupling in Java
  • What is Trim method in Java and How to Implement it?
Objects and Classes
  • Packages in Java: How to Create and Use Packages in Java?
  • Java Objects and Classes – Learn how to Create & Implement
  • What is Object in Java and How to use it?
  • Singleton Class in Java – How to Use Singleton Class?
  • What are the different types of Classes in Java?
  • What is a Robot Class in Java?
  • What is Integer class in java and how it works?
  • What is System Class in Java and how to implement it?
  • What is the role for a ClassLoader in Java?
  • Char in Java: What is Character class in Java?
  • What is the Boolean Class in Java and how to use it?
Java OOPS
  • Object Oriented Programming – Java OOPs Concepts With Examples
  • Inheritance in Java – Mastering OOP Concepts
  • Polymorphism in Java – How To Get Started With OOPs?
  • How To Implement Multiple Inheritance In Java?
  • Java Abstraction- Mastering OOP with Abstraction in Java
  • Encapsulation in Java – How to master OOPs with Encapsulation?
  • How to Implement Nested Class in Java?
  • What is the Use of Abstract Method in Java?
  • What is Association in Java and why do you need it?
  • What is the difference between Abstract Class and Interface in Java?
  • What is Runnable Interface in Java and how to implement it?
  • What is Cloning in Java and its Types?
  • What is Semaphore in Java and its use?
  • What is Dynamic Binding In Java And How To Use It?
Java Collections
  • Java Collections – Interface, List, Queue, Sets in Java With Examples
  • List in Java: One Stop Solution for Beginners
  • Java ArrayList: A Complete Guide for Beginners
  • Linked List in Java: How to Implement a Linked List in Java?
  • What are Vector in Java and how do we use it?
  • What is BlockingQueue in Java and how to implement it?
  • How To Implement Priority Queue In Java?
  • What is Deque in Java and how to implement its interface?
  • What are the Legacy Classes in Java?
  • Java HashMap – Know How to Implement HashMap in Java
  • What is LinkedHashSet in Java? Understand with examples
  • How to Implement Map Interface in Java?
  • Trees in Java: How to Implement a Binary Tree?
  • What is the Difference Between Extends and Implements in Java?
  • How to Implement Shallow Copy and Deep Copy in Java
  • How to Iterate Maps in Java?
  • What is an append Method in Java?
  • How To Implement Treeset In Java?
  • Java HashMap vs Hashtable: What is the difference?
  • How to Implement Method Hiding in Java
  • How To Best Implement Concurrent Hash Map in Java?
  • How To Implement Marker Interface In Java?
Java Programs
  • Palindrome in Java: How to check a number is palindrome?
  • How to check if a given number is an Armstrong number or not?
  • How to Find the largest number in an Array in Java?
  • How to find the Sum of Digits in Java?
  • How To Convert String To Date In Java?
  • Ways For Swapping Two Numbers In Java
  • How To Implement Addition Of Two Numbers In Java?
  • How to implement Java program to check Leap Year?
  • How to Calculate Square and Square Root in Java?
  • How to implement Bubble Sort in Java?
  • How to implement Perfect Number in Java?
  • What is Binary Search in Java? How to Implement it?
  • How to Perform Merge Sort in Java?
  • Top 30 Pattern Program in Java: How to Print Star, Number and Character
  • Know all about the Prime Number program in Java
  • How To Display Fibonacci Series In Java?
  • How to Sort Array, ArrayList, String, List, Map and Set in Java?
  • How To Create Library Management System Project in Java?
  • How To Practice String Concatenation In Java?
  • How To Convert Binary To Decimal In Java?
  • How To Convert Double To Int in Java?
  • How to convert Char to Int in Java?
  • How To Convert Char To String In Java?
  • How to Create JFrame in Java?
  • What is Externalization in Java and when to use it?
  • How to read and parse XML file in Java?
  • How To Implement Matrix Multiplication In Java?
  • How To Deal With Random Number and String Generator in Java?
  • Basic Java Programs for Practice With Examples
Advance Java
  • How To Connect To A Database in Java? – JDBC Tutorial
  • Advanced Java Tutorial- A Complete Guide for Advanced Java
  • Servlet and JSP Tutorial- How to Build Web Applications in Java?
  • Introduction to Java Servlets – Servlets in a Nutshell
  • What Is JSP In Java? Know All About Java Web Applications
  • How to Implement MVC Architecture in Java?
  • What is JavaBeans? Introduction to JavaBeans Concepts
  • Know what are the types of Java Web Services?
  • JavaFX Tutorial: How to create an application?
  • What is Executor Framework in Java and how to use it?
  • What is Remote Method Invocation in Java?
  • Everything You Need To Know About Session In Java?
  • Java Networking: What is Networking in Java?
  • What is logger in Java and why do you use it?
  • How To Handle Deadlock In Java?
  • Know all about Socket Programming in Java
  • Important Java Design Patterns You Need to Know About
  • What is ExecutorService in Java and how to create it?
  • Struts 2 Tutorial – One Stop Solution for Beginners
  • What is Hibernate in Java and Why do we need it?
  • What is Maven in Java and how do you use it?
  • What is Machine Learning in Java and how to implement it?
Career Opportunities
  • Java Developer Resume: How to Build an Impressive Resume?
  • What is the Average Java Developer Salary?
Interview Questions
  • Java Interview Questions and Answers
  • Top MVC Interview Questions and Answers for 2025
  • Top 50 Java Collections Interview Questions You Need to Know in 2025
  • Top 50 JSP Interview Questions You Need to Know in 2025
  • Top 50 Hibernate Interview Questions That Are A Must in 2025

Programming & Frameworks

Topics Covered
  • C Programming and Data Structures (16 Blogs)
  • Comprehensive Java Course (5 Blogs)
  • Java/J2EE and SOA (341 Blogs)
  • Spring Framework (9 Blogs)
SEE MORE Programming & Frameworks blog posts What is Dynamic Array in Java? Last updated on Jun 17,2021 32.2K Views Shareimage not found!WhatsAppimage not found!Linkedinimage not found!Twitterimage not found!Facebookimage not found!Redditimage not found!Copy Link! edureka edureka
  • Bookmark
image not found!image not found!image not found!image not found!image not found!image not found!Copy Link! Become a Certified Professional

Arrays in Java are homogeneous data structures implemented in Java as objects. Arrays store one or more values of a specific data type and provide indexed access to store the same. A specific element in an array is accessed by its index. In this article, we will discuss Dynamic Array in Java in the following sequence:

Table of Content
  1. Introduction to Dynamic Array in Java
  2. Size vs. Capacity
  3. Doubling Appends
  4. Deleting an Element
  5. Resizing an Array
  • Introduction to Dynamic Array in Java
  • Size vs Capacity
  • Doubling Appends
  • Deleting an Element
  • Resizing a Dynamic Array in Java

Introduction to Dynamic Array in Java

The dynamic array is such a type of an array with a huge improvement for automatic resizing. The only limitation of arrays is that it is a fixed size. This translates into a meaning that you can only specify the number of elements that your array can hold ahead of time. On the other hand, the dynamic arrays can expand as we add more elements in real-time. Therefore, the coder does not need to determine the size of the array ahead of time. It does have a few more strengths as well:

  • Quick lookup. Same as just like arrays, when retrieving the element at a given index, takes O (1) time.

  • Variable size. We can insert as many elements as we want and a dynamic array will accordingly expand to hold them.

  • Cache-friendly. Similar to arrays, dynamic arrays can put items next to each other in memory, thus making efficient utilization of caches.

There are some downsides to using dynamic arrays in our code. Although, we do use dynamic arrays more than anything does in most applications there are some cases where they do not become the most preferred choice due to its limitations.

  • Slow worst-case appends. Normally, while the addition of a new element at the end of a dynamic array, it takes O (1) at one instance. However, if the dynamic array does not have any more indices for a new item, then it will need to expand, which takes O (n) at a time.

  • Costly inserts and deletes. Similar to arrays, the elements are stored adjacent to each other. So while adding or removing an item in the center of an array it requires pushing other elements, which takes O (n) at a time.

The below diagrams show how the arrays work in real-time and depict how the elements are stacked up. It also shows how the instructions change for an average case and the worst case of array functions.

array - dynamic array in java - edureka

Size vs. Capacity

When we initialize a dynamic array, the dynamic array implementation creates an understood fixed-size array. The initial size corresponds to the implementation. For example, let us make our implementation array to use 10 indices. Now we append four items to our dynamic array. Now, our dynamic array has a length of four. However, our underlying array has a length of 10. Hence, we could say that dynamic array size is four and its capacity is 10. A dynamic array stores a specific end Index to keep track of the ending point of the dynamic array and the starting point from where the extra capacity begins.

size - dynamic array in javascript - edureka

Doubling Appends

There can be cases where we try to append an item to an array where the capacity is already full. Hence, to create room dynamic arrays automatically create new, bigger and underlying array. Usually, it becomes twice as big to handle any new additions, which it did not anticipate earlier. Hence, copying each item consumes no time. Whenever appending an item to our dynamic array automatically makes a new double-size underlying array, which append takes no time.

Deleting an Element

While deleting an element from an array, the default “remove()” method removes an element from the end and automatically stores zero at the last index. It will also delete elements at a specific index by calling removeAt(i) method where “I” is index. The removeAt(i) method shifts all the right elements in the left side from the given index.

delete - dynamic array in java - edureka

Resizing an Array

When arrays have no data at the right side of the array which than take unnecessary memory, the method srinkSize() frees extra memory. When all slots are consumed and additional elements are added, the underlying fixed-size array has to increase size. The actual resizing is expensive, as we have to allocate a bigger array and copy forward all elements from an array you have overgrown before it can finally append a new item.

resize - dynamic array in java - edureka

Below is an example of a program where the array size becomes full and new elements are copied to a new double size array. The element which is a string element called “Mahavir” is an addition to the already full array of size 3.

import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class AddingItemsDynamically { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size of the array :: "); int size = sc.nextInt(); String myArray[] = new String[size]; System.out.println("Enter elements of the array (Strings) :: "); for(int i=0; i<size; i++) { myArray[i] = sc.next(); } System.out.println(Arrays.toString(myArray)); ArrayList<String> myList = new ArrayList<String>(Arrays.asList(myArray)); System.out.println("Enter the element that is to be added:"); String element = sc.next(); myList.add(element); myArray = myList.toArray(myArray); System.out.println(Arrays.toString(myArray)); } }

Output:

With this, we come to the end of Dynamic Array in Java article. I hope you got an idea of how to work with dynamic arrays.

Check out theJava Online Course by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe. Edureka’s Java J2EE and SOA training and certification course is designed for students and professionals who want to be a Java Developer. The course is designed to give you a head start into Java programming and train you for both core and advanced Java concepts along with various Java frameworks like Hibernate & Spring.

Got a question for us? Please mention it in the comments section of this “Dynamic Array in Java” blog and we will get back to you as soon as possible.

Recommended videos for you

hibernate-the-ultimate-orm-framework.jpg

Hibernate-the ultimate ORM framework

Watch Now create-restful-web-application-with-node-js-express.jpg

Create Restful Web Application With Node.js Express

Watch Now spring-framework-introduction-to-spring-web-mvc-spring-with-bigdata.jpg

Spring Framework : Introduction to Spring Web MVC & Spring with BigData

Watch Now node-js-steps-to-create-restful-web-app.jpg

Node JS : Steps to Create Restful Web App

Watch Now learn-perl-the-jewel-of-scripting-languages.jpg

Learn Perl-the Jewel of Scripting Languages

Watch Now php-mysql-server-side-scripting-language-for-web-development.jpg

PHP & MySQL : Server-side Scripting Language for Web Development

Watch Now ms-net-an-intellisense-way-of-web-development.jpg

MS .Net – An IntelliSense Way of Web Development

Watch Now JAVA-J2EE-WEBINAR-600x3501_-300x175.png

Introduction to JAVA/J2EE & SOA

Watch Now microsoft-sharepoint-2013-the-ultimate-enterprise-collaboration-platform.jpg

Microsoft SharePoint 2013 : The Ultimate Enterprise Collaboration Platform

Watch Now rapid-development-with-cakephp.jpg

Rapid Development With CakePHP

Watch Now implementing-web-services-in-java.jpg

Implementing Web Services In Java

Watch Now microsoft-sharepoint-2013-the-ultimate-enterprise-collaboration-platform.jpg

Microsoft Sharepoint 2013 : The Ultimate Enterprise Collaboration Platform

Watch Now php-and-mysql-server-side-scripting-for-web-development.jpg

PHP and MySQL : Server Side Scripting For Web Development

Watch Now effective-persistence-using-orm-with-hibernate.jpg

Effective Persistence Using ORM With Hibernate

Watch Now a-day-in-the-life-of-a-node-js-developer.jpg

A Day In The Life Of A Node.js Developer

Watch Now responsive-web-app-using-cakephp.jpg

Responsive WEB APP using cakePHP

Watch Now microsoft-sharepoint-the-ultimate-enterprise-collaboration-platform.jpg

Microsoft SharePoint-The Ultimate Enterprise Collaboration Platform

Watch Now portal-development-and-text-searching-with-hibernate.jpg

Portal Development and Text Searching with Hibernate

Watch Now node-js-express-steps-to-create-restful-web-app.jpg

Node JS Express: Steps to Create Restful Web App

Watch Now mastering-regex-in-perl.jpg

Mastering Regex in Perl

Watch Now

Recommended blogs for you

Java-String-300x175.png

Learn How to Declare String in Java with Examples

Read Article Java-career-opportunities-300x175.jpg

Your Guide To Java Career Opportunities: How To Bag Top Java Jobs

Read Article Java-Networking-Blog-Feature-300x175.jpg

Java Networking: What is Networking in Java?

Read Article Blog_Servlet-JSP-tutorial-300x175.png

Servlet and JSP Tutorial- How to Build Web Applications in Java?

Read Article Read-and-write-Excel-and-CSV-file-in-Java-300x175.jpg

How to Read and Write Excel file in Java

Read Article Bootstrap-List-300x175.jpg

What is bootstrap list and how to use bootstrap list group?

Read Article Machine-learning-in-Java-300x175.jpg

What is Machine Learning in Java and how to implement it?

Read Article Daemon-Thread-in-Java-300x175.jpg

Daemon Thread in Java: Know what are it’s methods

Read Article Command-Line-Arguments-in-Java-300x175.jpg

How to Implement Command Line Arguments in Java

Read Article header-location-in-php-300x175.jpg

What Is Header Location In PHP?

Read Article Rest_Blog_11-300x175.png

How to Write RESTful Web Services With JAX-WS

Read Article sets-in-java-1-300x165.jpg

Sets In Java: Know how to work with Java Set Interface

Read Article blog_Introduction-to-Java-Servlets-300x175.jpg

Introduction to Java Servlets – Servlets in a Nutshell

Read Article Why-java-300x175.png

Why Java is a Popular Programming Language?

Read Article Top-10-Best-Java-IDE-300x175.jpg

Top 10 popular Java IDE: Choose the Best IDE for Java

Read Article Spring-Boot-Interview-Questions-blg-300x175.png

Top 60+ Spring Boot Interview Questions That Are A Must in 2025

Read Article list-in-Java-300x175.png

List in Java: One Stop Solution for Beginners

Read Article Access-modifiers-in-Java-300x175.jpg

Access Modifiers in Java: All you need to know

Read Article image-1-300x175.png

Top Data Structures & Algorithms in Java That You Need to Know

Read Article variables-in-java-300x175.jpg

Everything you need to know about Variables in Java

Read Article Comments 0 Comments

Join the discussionCancel reply

Trending Courses in Programming & Frameworks

Java Course Online

Java Course Online

  • 82k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 4 (30350) Full Stack Development Internship Program

Full Stack Development Internship Program

  • 29k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (11300) Python Scripting Certification Training

Python Scripting Certification Training

  • 15k Enrolled Learners
  • Weekend
  • Self Paced
Reviews 5 (5850) Flutter App Development Certification Course

Flutter App Development Certification Course

  • 13k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (4800) Node JS Course with Certification

Node JS Course with Certification

  • 11k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (3850) Spring Framework Certification Course

Spring Framework Certification Course

  • 13k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (4950) Data Structures and Algorithms using Java Internship Program

Data Structures and Algorithms using Java Int ...

  • 31k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (12050) Comprehensive Java Course Certification Training

Comprehensive Java Course Certification Train ...

  • 19k Enrolled Learners
  • Weekend/Weekday
  • Self Paced
Reviews 5 (7250) Advanced Java Certification Training

Advanced Java Certification Training

  • 7k Enrolled Learners
  • Weekend/Weekday
  • Self Paced
Reviews 5 (2800) Microsoft .NET Framework Certification Training

Microsoft .NET Framework Certification Traini ...

  • 6k Enrolled Learners
  • Weekend/Weekday
  • Self Paced
Reviews 5 (2350)

Browse Categories

Artificial IntelligenceAWSBI and VisualizationBig DataBlockchainBusiness ManagementCloud ComputingCyber SecurityData ScienceData Warehousing and ETLDatabasesDevOpsDigital MarketingEnterpriseFront End Web DevelopmentHuman Resource ManagementInterview QuestionsMobile DevelopmentOperating SystemsOperations ManagementProduct ManagementProject Management and MethodologiesRobotic Process Automationseo interview questionSoftware TestingStrategy and LeadershipSupply Chain ManagementSystems & Architecture webinar REGISTER FOR FREE WEBINAR Years of Experience*Student0-2 Years2-5 Years5-10 Years10+ Years REGISTER NOW webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

Google Sign up with Google facebook Signup with Facebook

Already have an account? Sign in.

20,00,000 learners love us! Get personalised resources in your inbox.

with Gmail with Facebook

OR

Password must have

At least 1 upper-case and 1 lower-case letter

Minimum 8 characters and Maximum 50 characters

SIGN UP Forgot Password? LOGIN resend ? Password must have

At least 1 upper-case and 1 lower-case letter

Minimum 8 characters and Maximum 50 characters

reset password reset password Send Code imagReshape Your Career! Name* Email ID* Phone Number* Your Total Work Experience* Years of Experience*Student0-2 Years2-5 Years5-10 Years10+ Years Apply Now

Awesome

We have recieved your contact details.

You will recieve an email from us shortly.

imageMain headingsub heading Click to avail "PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc. image not found! image not found!

What is Dynamic Array in Java?

edureka.co

image not found! Whatsapp image not found! Linkedin image not found! Twitter image not found! Facebook image not found! Reddit Copy Link image not found!

Tag » Add Element Dynamic Array Java