Example Analysis of Java Array Code
This article is to share with you about the example analysis of Java array code, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Array classification
1. One-dimensional array
1.1 definition and initialization of one-dimensional array
1.2 operations on one-dimensional arrays, traversing, adding, inserting, modifying, deleting, sorting, finding
two。 Two-dimensional array
2.1 definition and initialization of two-dimensional arrays
2.2 traversal of two-dimensional arrays
* / public class ArrayAppend {public static void main (String [] args) {/ / one-dimensional array definition and initialization / / static definition one-dimensional array int [] scores = {90, 70, 50, 80, 60, 85}; / / add a student's score 75 to the end of the one-dimensional array scores. / * ideas: 1. First create a temporary array tempArray 2. 1 that is 1 longer than the original scores array. Copy each value of the scores array to tempArray 3. 0. Then assign a score of 75 to tempArray's new final index position 4. 5. Finally, the tempArray address pointer reference is assigned to scores; * / int [] tempArray = new int [scores.length + 1]; for (int I = 0; I < scores.length; ipointer +) {tempArray [I] = scores [I];} tempArray [scores.length] = 75; scores = tempArray / / printout scores for (int I = 0; I < scores.length; iTunes +) {System.out.print (score [I] + ",");} above is the example analysis of the Java array code. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.