Example Analysis of java Array
This article shares with you the content of the sample analysis of the java array. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Java array
1) form of declaration:
Type [] arrayName; recommendation method
Type arrayName []
2) initialization: method 1: type [] arrayName;arrayName = new type [] {element1, element2, element3,...} method 2: type [] arrayName = {element1, element2, element3,...} method 3: report an error type [] arrayName;arrayName = {element1, element2, element3,...} mode 4: type [] arrayName = new type [length] Description: in mode 4, the system assigns initial values to array elements, such as byte,int long-> 0, float,double-> 0, boolean-> false, and reference type-> null. Do not specify the length of the array when initializing the array, but assign an initial value to each element. The array length is an attribute of the array, arrayName.length, which can be accessed. Foreach loop method: for (type var: array | collection) {.} Note: in this method, var is only a copy of the original collection. Modifying var will not change the content of the original collection. 3) Multidimensional array type [] [] arrName = new type [length] []; / / you can only specify high-dimensional type [] [] arrName = new type [length2] [length3]; String [] [] str1 = new String [] [] {new String [3], new String [] {"hello"}} / / visible low-dimensional lengths can be unequal 4) manipulate array tools such as ArraysbinarySearch, copyOf, sort, toString, etc. (supplementary use cases) Thank you for reading! This is the end of this article on "sample Analysis of java Array". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!