![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Dump the content of an array in Java
An array can be easily printed by using the method java.util.Arrays.toString() in Java. This method returns a string representation of the array contents that is enclosed in square brackets. If the array is null, then this method returns null.
A program that demonstrates this is given as follows −
Example
import java.util.Arrays; public class Demo { public static void main(String args[]) { String str[] = {"John", "Harry", "Sally", "Emma", "Peter"}; System.out.println("The array content is:"); System.out.println(Arrays.toString(str)); } }
Output
The array content is: [John, Harry, Sally, Emma, Peter]
Now let us understand the above program.
The string array str[] is defined. Then the array content is printed using the Arrays.toString() method. A code snippet which demonstrates this is as follows −
String str[] = {"John", "Harry", "Sally", "Emma", "Peter"}; System.out.println("The array content is:"); System.out.println(Arrays.toString(str));
Advertisements