This article will introduce to you what an array is in Java. I hope it will be helpful to friends in need!
Arrays are one of the important data structures for every programming language. Of course, different languages implement and process arrays differently.
Arrays provided in the Java language are used to store fixed-size elements of the same type.
You can declare an array variable, such as numbers[100] instead of directly declaring 100 independent variables number0, number1, ...., number99.
Declare array variables
First, you must declare an array variable before you can use the array in the program. The following is the syntax for declaring array variables:
dataType[] arrayRefVar; // 首选的方法
or
dataType arrayRefVar[]; // 效果相同,但不是首选方法
Note: It is recommended to use the declaration style of dataType[] arrayRefVar to declare array variables. The dataType arrayRefVar[] style comes from the C/C language and is adopted in Java to allow C/C programmers to quickly understand the java language.
Examples
The following are code examples for these two syntaxes:
double[] myList; // 首选的方法
or
double myList[]; // 效果相同,但不是首选方法
Creating an array
Java language uses the new operator to create an array. The syntax is as follows:
arrayRefVar = new dataType[arraySize];
The above syntax statement does two things:
1. Use dataType[arraySize] to create an array.
2. Assign the reference of the newly created array to the variable arrayRefVar.
The declaration of array variables and the creation of an array can be completed in one statement, as shown below:
dataType[] arrayRefVar = new dataType[arraySize];
In addition, you can also create an array in the following way.
dataType[] arrayRefVar = {value0, value1, ..., valuek};
The elements of the array are accessed by index. Array indexing starts at 0, so index values range from 0 to arrayRefVar.length-1.
Related recommendations: "Java Tutorial"
The above is the detailed content of What is an array in JAVA?. For more information, please follow other related articles on the PHP Chinese website!

Start Spring using IntelliJIDEAUltimate version...

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

Java...

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...


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

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software