Skip To Content3
Skip To Content3
geeksforgeeks
Courses 90% Refund
Tutorials
Java
Practice
Contests
Sign In
Java Arrays
Java Strings
Java OOPs
Java Collection
Java 8 Tutorial
Java Multithreading
Java Exception Handling
Java Programs
Java Project
Java Collections Interview
Java Interview Questions
Java MCQs
Spring
Spring MVC
Spring Boot
Hibernate
The java.util.Arrays class contains various methods for manipulating arrays (such
as sorting and searching), whereas this java.lang.reflect.Array class provides
static methods to create and access Java arrays dynamically. This Array class keeps
the array to be type-safe.
Class Hierarchy
java.lang.Object
↳ java.lang.reflect.Array
Class Declaration
public final class Array
Note: The Array class should be correctly represented as public final class Array.
It extends Object implicitly but does not explicitly declare extends Object.
This method returns an Object array of the given size, then cast into the required
X[] type.
Hence the required array of type X has been created.
Below is an example to create an integer array of size 5, using the Array class:
import java.lang.reflect.Array;
import java.util.Arrays;
Output
[0, 0, 0, 0, 0]
How to add elements in an Array using java.lang.reflect.Array Class?
Like creating an array, adding elements in the array using reflect.Array Class is
also different from the usual way. The process to add elements in such an array is
as follows:
This method inserts the element at the specified index in this array.
Hence the required element has been inserted into the array.
Below is an example to add an element into an integer array, using the Array class:
import java.lang.reflect.Array;
import java.util.Arrays;
Output
[10, 20, 30]
How to retrieve elements in an Array using java.lang.reflect.Array Class?
Like creating an array, retrieving elements in the array using reflect.Array Class
is also different from the usual way. The process to retrieve elements in such an
array is as follows:
Array.getX(X[], indexOfRetrieval);
Where X is to be replaced by the type of the array like int, double, etc.
This method retrieves the element at the specified index from this array.
Hence the required element has been retrieved from the array.
Below is an example to retrieve an element from an integer array using the Array
class:
import java.lang.reflect.Array;
import java.util.Arrays;
Output
[10, 20, 30]
Element at index 0: 10
Element at index 1: 20
Element at index 2: 30
Three 90 Challenge is back on popular demand! After processing refunds worth INR
1CR+, we are back with the offer if you missed it the first time. Get 90% course
fee refund in 90 days. Avail now!
Want to be a master in Backend Development with Java for building robust and
scalable applications? Enroll in Java Backend and Development Live Course by
GeeksforGeeks to get your hands dirty with Backend Programming. Master the key Java
concepts, server-side programming, database integration, and more through hands-on
experiences and live projects. Are you new to Backend development or want to be a
Java Pro? This course equips you with all you need for building high-performance,
heavy-loaded backend systems in Java. Ready to take your Java Backend skills to the
next level? Enroll now and take your development career to sky highs.
RishabhPrabhu
19
Previous Article
Final Arrays in Java
Next Article
util.Arrays vs reflect.Array in Java with Examples
Read More
Down Arrow
Similar Reads
How to call private method from another class in Java with help of Reflection API?
We can call the private method of a class from another class in Java (which is
defined using the private access modifier in Java). We can do this by changing the
runtime behavior of the class by using some predefined methods of Java. For
accessing private methods of different classes we will use Reflection API. To call
the private method, we will u
3 min read
Reflection in Java
Reflection is an API that is used to examine or modify the behavior of methods,
classes, and interfaces at runtime. The required classes for reflection are
provided under java.lang.reflect package which is essential in order to understand
reflection. So we are illustrating the package with visual aids to have a better
understanding as follows: Refl
5 min read
How to Invoke Method by Name in Java Dynamically Using Reflection?
Java Reflection API provides us information about a Class to which the Object
belongs to including the methods in this class. Using these Reflection API we would
be able to get invoking pointer for a method in a class with its name. There are
two functions used for this purpose: Invoking method with its nameFinding a method
by Name in a class and i
4 min read
How to prevent Singleton Pattern from Reflection, Serialization and Cloning?
Prerequisite: Singleton Pattern In this article, we will see what various concepts
can break the singleton property of a class and how to avoid them. There are mainly
3 concepts that can break the singleton property of a class. Let's discuss them one
by one. Reflection: Reflection can be caused to destroy singleton property of the
singleton class,
6 min read
Java.lang.Class class in Java | Set 1
Java provides a class with name Class in java.lang package. Instances of the class
Class represent classes and interfaces in a running Java application. The primitive
Java types (boolean, byte, char, short, int, long, float, and double), and the
keyword void are also represented as Class objects. It has no public constructor.
Class objects are cons
15+ min read
Java.lang.Class class in Java | Set 2
Java.lang.Class class in Java | Set 1 More methods: 1. int getModifiers() : This
method returns the Java language modifiers for this class or interface, encoded in
an integer. The modifiers consist of the Java Virtual Machine's constants for
public, protected, private, final, static, abstract and interface. These modifiers
are already decoded in Mo
15+ min read
Difference Between java.sql.Time, java.sql.Timestamp and java.sql.Date in Java
Across the software projects, we are using java.sql.Time, java.sql.Timestamp and
java.sql.Date in many instances. Whenever the java application interacts with the
database, we should use these instead of java.util.Date. The reason is JDBC i.e.
java database connectivity uses these to identify SQL Date and Timestamp. Here let
us see the differences
7 min read
Java.util.TimeZone Class (Set-2) | Example On TimeZone Class
TimeZone class (the methods of this class was discussed in this article
Java.util.TimeZone Class | Set 1) can be used in many cases like using TimeZone
class we can get the time difference in term of hour and minute between two
places.Problem : How we can get time difference of time in terms of hours and
minutes between two places of Earth?Solution
5 min read
Implement Pair Class with Unit Class in Java using JavaTuples
To implement a Pair class with a Unit class in Java using JavaTuples, you can use
the Pair class provided by the library and create a new Unit class that extends the
Unit class provided by the library. Here is an example implementation: Here is an
example Java code that uses the MyPair class with MyUnit and displays the output:
Java Code import org
4 min read
Implement Triplet Class with Pair Class in Java using JavaTuples
Following are the ways to implement Triplet Class with Pair Class Using direct
values import java.util.*; import org.javatuples.*; class GfG { public static void
main(String[] args) { // create Pair Pair<Integer, String> pair = new
Pair<Integer, String>( Integer.valueOf(1), "GeeksforGeeks"); //
Print the Pair System.out.printl
2 min read
Article Tags :
Java
Java-Class and Object
java-reflection-array
Practice Tags :
Java
Java-Class and Object
three90RightbarBannerImg
course-img
215k+ interested Geeks
Master Java Programming - Complete Beginner to Advanced
Explore
course-img
214k+ interested Geeks
JAVA Backend Development - Live
Explore
course-img
30k+ interested Geeks
Manual to Automation Testing: A QA Engineer's Guide
Explore
geeksforgeeks-footer-logo
Corporate & Communications Address:- A-143, 9th Floor, Sovereign Corporate Tower,
Sector- 136, Noida, Uttar Pradesh (201305) | Registered Address:- K 061, Tower K,
Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh,
201305
GFG App on Play Store
GFG App on App Store
Company
About Us
Legal
Careers
In Media
Contact Us
Advertise with us
GFG Corporate Solution
Placement Training Program
Explore
Job-A-Thon Hiring Challenge
Hack-A-Thon
GfG Weekly Contest
Offline Classes (Delhi/NCR)
DSA in JAVA/C++
Master System Design
Master CP
GeeksforGeeks Videos
Geeks Community
Languages
Python
Java
C++
PHP
GoLang
SQL
R Language
Android Tutorial
DSA
Data Structures
Algorithms
DSA for Beginners
Basic DSA Problems
DSA Roadmap
DSA Interview Questions
Competitive Programming
Data Science & ML
Data Science With Python
Data Science For Beginner
Machine Learning Tutorial
ML Maths
Data Visualisation Tutorial
Pandas Tutorial
NumPy Tutorial
NLP Tutorial
Deep Learning Tutorial
Web Technologies
HTML
CSS
JavaScript
TypeScript
ReactJS
NextJS
NodeJs
Bootstrap
Tailwind CSS
Python Tutorial
Python Programming Examples
Django Tutorial
Python Projects
Python Tkinter
Web Scraping
OpenCV Tutorial
Python Interview Question
Computer Science
GATE CS Notes
Operating Systems
Computer Network
Database Management System
Software Engineering
Digital Logic Design
Engineering Maths
DevOps
Git
AWS
Docker
Kubernetes
Azure
GCP
DevOps Roadmap
System Design
High Level Design
Low Level Design
UML Diagrams
Interview Guide
Design Patterns
OOAD
System Design Bootcamp
Interview Questions
School Subjects
Mathematics
Physics
Chemistry
Biology
Social Science
English Grammar
Commerce
Accountancy
Business Studies
Economics
Management
HR Management
Finance
Income Tax
Databases
SQL
MYSQL
PostgreSQL
PL/SQL
MongoDB
Preparation Corner
Company-Wise Recruitment Process
Resume Templates
Aptitude Preparation
Puzzles
Company-Wise Preparation
Companies
Colleges
Competitive Exams
JEE Advanced
UGC NET
UPSC
SSC CGL
SBI PO
SBI Clerk
IBPS PO
IBPS Clerk
More Tutorials
Software Development
Software Testing
Product Management
Project Management
Linux
Excel
All Cheat Sheets
Recent Articles
Free Online Tools
Typing Test
Image Editor
Code Formatters
Code Converters
Currency Converter
Random Number Generator
Random Password Generator
Write & Earn
Write an Article
Improve an Article
Pick Topics to Write
Share your Experiences
Internships
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By
using our site, you acknowledge that you have read and understood our Cookie Policy
& Privacy Policy
Got It !
Lightbox