What are the methods to print one-dimensional array in java
1. Three ways to output arrays
One-dimensional array:
Define an array int[] array = {1,2, 3,4,5};
(1) Traditional for loop method
for(int i=0;i<array.length;i++) { System.out.println(a[i]); }
(2) for each loop
for(int a:array) System.out.println(a);
(3) Use the toString method in the Array class
to call Array.toString(a) to return a string containing array elements, which are placed within brackets. And separate them with commas
int[] array = {1,2,3,4,5}; System.out.println(Arrays.toString(array));
Output: [1, 2, 3, 4, 5]
Explanation: System.out.println(array); This is not possible, print like this Yes, it is the first address of the array.
Recommended tutorial: java introductory tutorial
The above is the detailed content of What are the methods to print one-dimensional array in java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download
The most popular open source editor