HOME
> System software
> Java Arrays: A Brief Tutorial - What You Should Know
Java Arrays: A brief tutorial - what you should know
Arrays are a data type used in Java and other programming languages. To generate a new array in Java, the same procedure is always used. Which command you need for a new array, we explain with an example.
A brief tutorial: This is the function of arrays in Java
Arrays belong to the data types in the Java programming language. Here, arrays are used to store multiple values, but they must all belong to the same type. This means that while you can store different primitive data types, objects or even other arrays in a new array, they must not be mixed. The length of the array is set directly when it is created and cannot be changed later, since an array is constant.How to declare arrays in Java
Since an array is an object, each new array is always defined using the "new" command. Here, the declaration is always done in the same way, by first specifying the data type that the array should have, followed by an opening and a closing square bracket.- Then you specify that it is an array and enter an equal sign as the assignment operator.
- Zum Schluss erfolgt rechts des Zuweisungsoperators noch die Angabe des Befehls „new“ und in eckigen Klammern wird die Länge des Arrays festgelegt.
- Um beispielsweise einen Array vom Typ „int“ zu erstellen, lautet der Befehl wie folgt: „int[] arr = new int[5];“.
- Wurde der Array deklariert, fahren Sie bitte mit der Initialisierung des Arrays fort, indem Sie den einzelnen Indices Werte zuweisen.