Java object-oriented programming -6.9

Array of objects
prior to contact with the basic data types are defined in the array, but the Java program itself, various types of data can be an array type, it can also be a class type array, such an array becomes the object array.
It defines an array format is as follows:

  • Dynamic initialization: the class name of the object array [] = new class of [length], the content of each element is null
  • Static initialization: the class name of the object array [] = new class [] {instantiate an object, the object is instantiated, ...}

Dynamic initialization

Static initialization

For an array of objects, itself just replace an array of so-called defined types.
Memory Analysis

A fixed array length of the defect
advantages linear access faster to access the index storage (time complexity is 1)

Guess you like

Origin www.cnblogs.com/sakura579/p/12388319.html