Professional Documents
Culture Documents
Anonymous Array in Java - GeeksforGeeks
Anonymous Array in Java - GeeksforGeeks
Anonymous Array in Java - GeeksforGeeks
Data Structures Algorithms Interview Preparation Topic-wise Practice C++ Java Python
just for creating and using instantly. Using an anonymous array, we can pass an array
We can create an array without a name. Such types of nameless arrays are called
anonymous arrays.
The main purpose of an anonymous array is just for instant use (just for one-time
usage).
Note : For Anonymous array creation, do not mention size in []. The number of
Syntax :
Examples :
//useanonymous
We char
cookies to ensure array
you have
browsing experience on our website. By using our site, you
acknowledge
the best
that you have read and understood our
Cookie Policy &
Privacy Policy
new char[] {'x', 'y', 'z');
Got It !
https://www.geeksforgeeks.org/anonymous-array-java/ 1/5
3/3/22, 9:58 PM Anonymous Array in Java - GeeksforGeeks
Implementation:
Java
Output
Explanation: In the above example, just to call the sum method, we required an
array, but af ter implementing the sum method, we are not using the array anymore.
Hence for this one-time requirement anonymous array is the best choice. Based on
our requirement, we can later give the name to the anonymous array, and then it will
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
no longer be anonymous.
that you have read and understood our
Cookie Policy &
Privacy Policy
Got It !
https://www.geeksforgeeks.org/anonymous-array-java/ 2/5
3/3/22, 9:58 PM Anonymous Array in Java - GeeksforGeeks
This ar ticle is contributed by Bishal Kumar Dubey. If you like GeeksforGeeks and
Login Register
or mail your ar ticle to review-team@geeksforgeeks.org. See your ar ticle appearing
on the GeeksforGeeks main page and help other Geeks. Please write comments if
you find anything incorrect, or you want to share more information about the topic
discussed above.
Like 8
Previous Next
https://www.geeksforgeeks.org/anonymous-array-java/ 3/5
3/3/22, 9:58 PM Anonymous Array in Java - GeeksforGeeks
java.util.Date in Java?
07 02, Feb 21
Start Inner
YourClass
Coding JourneyInner
And Anonymous Now! Login Register
04 Class that Implements Runnable | Different Ways to Convert
08
Concurrent Programming java.util.Date to
Approach 3 java.time.LocalDate in Java
08, Apr 19 05, Jan 21
Ar ticle Contributed By :
GeeksforGeeks
Current difficulty :
Easy
Improved By : nishkarshgandhi
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
Load Comments
that you have read and understood our
Cookie Policy &
Privacy Policy
Got It !
https://www.geeksforgeeks.org/anonymous-array-java/ 4/5
3/3/22, 9:58 PM Anonymous Array in Java - GeeksforGeeks
Company Learn
About Us Algorithms
Careers Data Structures
Privacy Policy Machine learning
Contact Us CS Subjects
Copyright Policy Video Tutorials
News Languages
Technology Python
Work & Career Java
Business CPP
Finance Golang
Lifestyle C#
@geeksforgeeks
, Some 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 !
https://www.geeksforgeeks.org/anonymous-array-java/ 5/5