Generic array list, mainly to solve the problem of dynamically changing arrays at runtime
Usually we define an array of people in a department,
But in real business, the size of this array is often indeterminate,
If the definition is too large, then the space is wasted, the definition is too small, and not enough,
In order to solve the problem of dynamically changing arrays at runtime, we propose the following solution.
Package com.ray.object;import java.util.arraylist;/** * Generic array list, resolving the problem of dynamically changing arrays at runtime * * @author Ray * @since 2015-05-04 * @ Version 1.0 * */public class Person {private int id = 0;public int getId () {return ID;} public void setId (int id) {this.id = ID;} public static void Main (string[] args) {//Normally we will define the people in a department as in the following statement//But in the actual business, the size of this array is often uncertain//if the definition is too large, then waste space, defined too small, Not enough//because in order to solve the problem of dynamically changing arrays at runtime, we propose the following solution//person[] persons = new person[100];//assemble a person's listarraylist<person> List = new arraylist<person> (); for (int i = 0, i < 5; i++) {Person temp = new person (); Temp.setid (i); List.add (tem p);} person[] persons = new Person[list.size ()];//through the method, the list is converted to the corresponding array list.toarray (persons); for (int i = 0; i < Persons.lengt H i++) {System.out.println (Persons[i].getid ());}}}
java-Basics-generic array list-resolves an issue in which arrays are dynamically changed at run time