what would be the name of class representing an array object? eg:
int a[] = new int[5]
here a is the reference variable. what is the name of class whoes object's reference id hold in a System.out.println(a.getClass().getName()) prints [I
is there any rule for naming?
Class name for Array in java
For Java arrays,the class name is '[' followed by an encoded name of the element class. The number of '[' character represent the number of dimension of the array
Element Type Encoding
byte B
boolean Z
char C
double D
float F
int I
long J
short S
class or interface Lclassname;
for example : for float type array class name is [F
for int [I
for double a[][]=new double[2][3]
class name is [[D
source: http://ohmjavaclasses.blogspot.com/2011/12/class-name-for-array-in-java.html
In general, your class should have a name taken from the problem domain model 's vocabulary.
Example: If you need to keep an array of books Book[] books
then a good bet would be to create a Library
class holding a reference to those books.
To comeback to your question, it depends on what a
will contain.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.