KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > lang > reflect > Array

java.lang.reflect
Class Array

java.lang.Object
  extended by java.lang.reflect.Array
See Also:
Top Examples, Source Code

public static Object get(Object array,
                         int index)
                  throws IllegalArgumentException,
                         ArrayIndexOutOfBoundsException
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static boolean getBoolean(Object array,
                                 int index)
                          throws IllegalArgumentException,
                                 ArrayIndexOutOfBoundsException
See Also:
get(java.lang.Object, int), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static byte getByte(Object array,
                           int index)
                    throws IllegalArgumentException,
                           ArrayIndexOutOfBoundsException
See Also:
get(java.lang.Object, int), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static char getChar(Object array,
                           int index)
                    throws IllegalArgumentException,
                           ArrayIndexOutOfBoundsException
See Also:
get(java.lang.Object, int), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static double getDouble(Object array,
                               int index)
                        throws IllegalArgumentException,
                               ArrayIndexOutOfBoundsException
See Also:
get(java.lang.Object, int), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static float getFloat(Object array,
                             int index)
                      throws IllegalArgumentException,
                             ArrayIndexOutOfBoundsException
See Also:
get(java.lang.Object, int), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int getInt(Object array,
                         int index)
                  throws IllegalArgumentException,
                         ArrayIndexOutOfBoundsException
See Also:
get(java.lang.Object, int), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int getLength(Object array)
                     throws IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[739]Array get length
By Anonymous on 2004/04/21 05:09:11  Rate
 
 poly [  ]  =  [ 3,4,5 ] ; 
 int len = Array.getLength ( poly ) ; 
 System.out.println ( len ) ;


public static long getLong(Object array,
                           int index)
                    throws IllegalArgumentException,
                           ArrayIndexOutOfBoundsException
See Also:
get(java.lang.Object, int), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static short getShort(Object array,
                             int index)
                      throws IllegalArgumentException,
                             ArrayIndexOutOfBoundsException
See Also:
get(java.lang.Object, int), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Object newInstance(Class<?> componentType,
                                 int length)
                          throws NegativeArraySizeException
See Also:
IllegalArgumentException, NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Object newInstance(Class<?> componentType,
                                 int[] dimensions)
                          throws IllegalArgumentException,
                                 NegativeArraySizeException
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void set(Object array,
                       int index,
                       Object value)
                throws IllegalArgumentException,
                       ArrayIndexOutOfBoundsException
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setBoolean(Object array,
                              int index,
                              boolean z)
                       throws IllegalArgumentException,
                              ArrayIndexOutOfBoundsException
See Also:
set(java.lang.Object, int, java.lang.Object), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setByte(Object array,
                           int index,
                           byte b)
                    throws IllegalArgumentException,
                           ArrayIndexOutOfBoundsException
See Also:
set(java.lang.Object, int, java.lang.Object), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setChar(Object array,
                           int index,
                           char c)
                    throws IllegalArgumentException,
                           ArrayIndexOutOfBoundsException
See Also:
set(java.lang.Object, int, java.lang.Object), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setDouble(Object array,
                             int index,
                             double d)
                      throws IllegalArgumentException,
                             ArrayIndexOutOfBoundsException
See Also:
set(java.lang.Object, int, java.lang.Object), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setFloat(Object array,
                            int index,
                            float f)
                     throws IllegalArgumentException,
                            ArrayIndexOutOfBoundsException
See Also:
set(java.lang.Object, int, java.lang.Object), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setInt(Object array,
                          int index,
                          int i)
                   throws IllegalArgumentException,
                          ArrayIndexOutOfBoundsException
See Also:
set(java.lang.Object, int, java.lang.Object), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setLong(Object array,
                           int index,
                           long l)
                    throws IllegalArgumentException,
                           ArrayIndexOutOfBoundsException
See Also:
set(java.lang.Object, int, java.lang.Object), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setShort(Object array,
                            int index,
                            short s)
                     throws IllegalArgumentException,
                            ArrayIndexOutOfBoundsException
See Also:
set(java.lang.Object, int, java.lang.Object), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1892]Initializing two-dimensional arrays
By Anonymous on 2007/06/15 13:02:58  Rate
* the first dimension represents the rows, the second dimension, the columns 
 * curly braces  {  }  may also be used to initialize two dimensional arrays. Again they are only valid in array declaration statements. 
  
  
   int [  ]  [  ]  twoDimArray =  {   { 1,2,3 } ,  { 4,5,6 } ,  { 7,8,9 }   } ; 
  
  
 * you can initialize the row dimension without initializing the columns but not vice versa 
  
  
   int [  ]  [  ]  myArray = new int [ 5 ]  [  ] ; 
   // illegal 
   int [  ]  [  ]  myArray = new int [  ]  [ 5 ] ;  
  
  
 * the length of the columns can vary 
  
  
  
 class TestTwoDimArrays  {  
   // initialize # of rows 
   static int  [  ]  [  ]  myArray = new int [ 3 ]  [  ] ;  
  
  
   public static void main ( String [  ]  args )   {  
  
  
   myArray [ 0 ]  = new int [ 3 ] ; // initialize # of cols 
   myArray [ 1 ]  = new int [ 4 ] ; // in each row 
   myArray [ 2 ]  = new int [ 5 ] ; 
  
  
   for ( int i=0; i < 3; i++ )     // fill and print the array 
       fillArray ( i, i+3 ) ; 
  
  
   System.out.println (  ) ; 
    }  // end main (  )  
  
  
   private static void fillArray ( int row, int col )   {  
  
  
       for (  int i=0; i < col; i++ )  
     myArray [ row ]  [ i ]  = i; 
  
  
       for (  int i=0; i < col; i++ )  
     System.out.print ( myArray [ row ]  [ i ]  ) ; 
  
  
       System.out.println (  ) ; 
    }  
  
  
  }  
  
  
 Output of TestTwoDimArrays: 
  
  
   012 
   0123 
   01234     
  
  
 

Popular Tags