Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the static initialization of Java array

Shulou Source: shulou.com Published: 2022-05-31 17:51:12 10月04日 Update

This article mainly introduces "how to realize the static initialization of Java array". In daily operation, I believe many people have doubts about how to realize the static initialization of Java array. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to realize the static initialization of Java array". Next, please follow the editor to study!

Concept

1. It refers to the execution of the contents of the static initialization block. When you create an array, you determine the element directly.

2. Format

Data type [] array name = new data type [] {element 1, element 2.}

Example

Package com.itheima.array2; public class Demo1Array {/ * array static initialization: specify the initial value of each array element during initialization, and the full format of the array length is determined by the system: data type [] array name = new data type [] {data 1, data 2, data 3.} Simplified format: data type [] array name = {data 1, data 2, data 3.}; * / public static void main (String [] args) {/ / data type [] array name = new data type [] {data 1, data 2, data 3.}; int [] arr = new int [] {112233} System.out.println (arr [0]); System.out.println (arr [1]); System.out.println (arr [2]); / / data type [] Array name = {data 1, data 2, data 3.}; int [] arr2 = {44 System.out.println (arr2); System.out.println (arr2 [0]) System.out.println (arr2 [1]); System.out.println (arr2 [2]);}} at this point, the study on "how to implement static initialization of Java arrays" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Data array type static element learning format more help practical next content example article method concept theory knowledge article system Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MySQL Huawei OPPO Reno Shulou Information