<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FReflection%2FArray</id>
		<title>Java Tutorial/Reflection/Array - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FReflection%2FArray"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Reflection/Array&amp;action=history"/>
		<updated>2026-04-23T02:40:46Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Reflection/Array&amp;diff=2975&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Reflection/Array&amp;diff=2975&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:26Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 17:44, 31 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Reflection/Array&amp;diff=2976&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Reflection/Array&amp;diff=2976&amp;oldid=prev"/>
				<updated>2010-05-31T15:19:39Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  Array reflection and two dimensional array ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 1995 - 2008 Sun Microsystems, Inc.  All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions of source code must retain the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *     documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Neither the name of Sun Microsystems nor the names of its&lt;br /&gt;
 *     contributors may be used to endorse or promote products derived&lt;br /&gt;
 *     from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS&lt;br /&gt;
 * IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
import static java.lang.System.out;&lt;br /&gt;
import java.lang.reflect.Array;&lt;br /&gt;
public class CreateMatrix {&lt;br /&gt;
  public static void main(String... args) {&lt;br /&gt;
    Object matrix = Array.newInstance(int.class, 2, 2);&lt;br /&gt;
    Object row0 = Array.get(matrix, 0);&lt;br /&gt;
    Object row1 = Array.get(matrix, 1);&lt;br /&gt;
    Array.setInt(row0, 0, 1);&lt;br /&gt;
    Array.setInt(row0, 1, 2);&lt;br /&gt;
    Array.setInt(row1, 0, 3);&lt;br /&gt;
    Array.setInt(row1, 1, 4);&lt;br /&gt;
    for (int i = 0; i &amp;lt; 2; i++)&lt;br /&gt;
      for (int j = 0; j &amp;lt; 2; j++)&lt;br /&gt;
        out.format(&amp;quot;matrix[%d][%d] = %d%n&amp;quot;, i, j, ((int[][]) matrix)[i][j]);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  class name for double and float array ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class ClassInfoDemo2 {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Class c = String.class;&lt;br /&gt;
    System.out.println(c.getName());&lt;br /&gt;
    c = ClassInfoDemo2.class;&lt;br /&gt;
    System.out.println(c.getName());&lt;br /&gt;
    c = double.class;&lt;br /&gt;
    System.out.println(c.getName());&lt;br /&gt;
    c = float[].class;&lt;br /&gt;
    System.out.println(c.getName());&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Create array with Array.newInstance ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 1995 - 2008 Sun Microsystems, Inc.  All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions of source code must retain the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *     documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Neither the name of Sun Microsystems nor the names of its&lt;br /&gt;
 *     contributors may be used to endorse or promote products derived&lt;br /&gt;
 *     from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS&lt;br /&gt;
 * IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
import static java.lang.System.out;&lt;br /&gt;
import java.lang.reflect.Array;&lt;br /&gt;
import java.lang.reflect.Constructor;&lt;br /&gt;
import java.lang.reflect.InvocationTargetException;&lt;br /&gt;
import java.util.Arrays;&lt;br /&gt;
import java.util.regex.Matcher;&lt;br /&gt;
import java.util.regex.Pattern;&lt;br /&gt;
public class ArrayCreator {&lt;br /&gt;
  private static String s = &amp;quot;java.math.BigInteger bi[] = { 123, 234, 345 }&amp;quot;;&lt;br /&gt;
  private static Pattern p = Pattern&lt;br /&gt;
      .rupile(&amp;quot;^\\s*(\\S+)\\s*\\w+\\[\\].*\\{\\s*([^}]+)\\s*\\}&amp;quot;);&lt;br /&gt;
  public static void main(String... args) {&lt;br /&gt;
    Matcher m = p.matcher(s);&lt;br /&gt;
    if (m.find()) {&lt;br /&gt;
      String cName = m.group(1);&lt;br /&gt;
      String[] cVals = m.group(2).split(&amp;quot;[\\s,]+&amp;quot;);&lt;br /&gt;
      int n = cVals.length;&lt;br /&gt;
      try {&lt;br /&gt;
        Class&amp;lt;?&amp;gt; c = Class.forName(cName);&lt;br /&gt;
        Object o = Array.newInstance(c, n);&lt;br /&gt;
        for (int i = 0; i &amp;lt; n; i++) {&lt;br /&gt;
          String v = cVals[i];&lt;br /&gt;
          Constructor ctor = c.getConstructor(String.class);&lt;br /&gt;
          Object val = ctor.newInstance(v);&lt;br /&gt;
          Array.set(o, i, val);&lt;br /&gt;
        }&lt;br /&gt;
        Object[] oo = (Object[]) o;&lt;br /&gt;
        out.format(&amp;quot;%s[] = %s%n&amp;quot;, cName, Arrays.toString(oo));&lt;br /&gt;
        // production code should handle these exceptions more gracefully&lt;br /&gt;
      } catch (ClassNotFoundException x) {&lt;br /&gt;
        x.printStackTrace();&lt;br /&gt;
      } catch (NoSuchMethodException x) {&lt;br /&gt;
        x.printStackTrace();&lt;br /&gt;
      } catch (IllegalAccessException x) {&lt;br /&gt;
        x.printStackTrace();&lt;br /&gt;
      } catch (InstantiationException x) {&lt;br /&gt;
        x.printStackTrace();&lt;br /&gt;
      } catch (InvocationTargetException x) {&lt;br /&gt;
        x.printStackTrace();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Create integer array with Array.newInstance ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 1995 - 2008 Sun Microsystems, Inc.  All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions of source code must retain the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *     documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Neither the name of Sun Microsystems nor the names of its&lt;br /&gt;
 *     contributors may be used to endorse or promote products derived&lt;br /&gt;
 *     from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS&lt;br /&gt;
 * IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
import static java.lang.System.out;&lt;br /&gt;
import java.lang.reflect.Array;&lt;br /&gt;
public class ArrayTrouble {&lt;br /&gt;
  public static void main(String... args) {&lt;br /&gt;
    Object o = Array.newInstance(int.class, 0);&lt;br /&gt;
    int[] i = (int[]) o;&lt;br /&gt;
    int[] j = new int[0];&lt;br /&gt;
    out.format(&amp;quot;i.length = %d, j.length = %d, args.length = %d%n&amp;quot;, i.length,&lt;br /&gt;
        j.length, args.length);&lt;br /&gt;
    Array.getInt(o, 0); // ArrayIndexOutOfBoundsException&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Demonstrates the use of the Array class ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 *     file: ArrayDemo.java&lt;br /&gt;
 *  package: oreilly.hcj.reflection&lt;br /&gt;
 *&lt;br /&gt;
 * This software is granted under the terms of the Common Public License,&lt;br /&gt;
 * CPL, which may be found at the following URL:&lt;br /&gt;
 * http://www-124.ibm.ru/developerworks/oss/CPLv1.0.htm&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright(c) 2003-2005 by the authors indicated in the @author tags.&lt;br /&gt;
 * All Rights are Reserved by the various authors.&lt;br /&gt;
 *&lt;br /&gt;
########## DO NOT EDIT ABOVE THIS LINE ########## */&lt;br /&gt;
&lt;br /&gt;
import java.lang.reflect.Array;&lt;br /&gt;
/**  &lt;br /&gt;
 * Demonstrates the use of the Array class.&lt;br /&gt;
 *&lt;br /&gt;
 * @author &lt;br /&gt;
 * @version $Revision$&lt;br /&gt;
 */&lt;br /&gt;
public class ArrayDemo {&lt;br /&gt;
  /** &lt;br /&gt;
   * Copy an array and return the copy.&lt;br /&gt;
   *&lt;br /&gt;
   * @param input The array to copy.&lt;br /&gt;
   *&lt;br /&gt;
   * @return The coppied array.&lt;br /&gt;
   *&lt;br /&gt;
   * @throws IllegalArgumentException If input is not an array.&lt;br /&gt;
   */&lt;br /&gt;
  public static Object copyArray(final Object input) {&lt;br /&gt;
    final Class type = input.getClass();&lt;br /&gt;
    if (!type.isArray()) {&lt;br /&gt;
      throw new IllegalArgumentException();&lt;br /&gt;
    }&lt;br /&gt;
    final int length = Array.getLength(input);&lt;br /&gt;
    final Class componentType = type.getComponentType();&lt;br /&gt;
    final Object result = Array.newInstance(componentType, length);&lt;br /&gt;
    for (int idx = 0; idx &amp;lt; length; idx++) {&lt;br /&gt;
      Array.set(result, idx, Array.get(input, idx));&lt;br /&gt;
    }&lt;br /&gt;
    return result;&lt;br /&gt;
  }&lt;br /&gt;
  /** &lt;br /&gt;
   * Run the demo.&lt;br /&gt;
   *&lt;br /&gt;
   * @param args Command line arguments (ignored).&lt;br /&gt;
   */&lt;br /&gt;
  public static void main(final String[] args) {&lt;br /&gt;
    try {&lt;br /&gt;
      int[] x = new int[] { 2, 3, 8, 7, 5 };&lt;br /&gt;
      char[] y = new char[] { &amp;quot;a&amp;quot;, &amp;quot;z&amp;quot;, &amp;quot;e&amp;quot; };&lt;br /&gt;
      String[] z = new String[] { &amp;quot;Jim&amp;quot;, &amp;quot;John&amp;quot;, &amp;quot;Joe&amp;quot; };&lt;br /&gt;
      System.out.println(&amp;quot; -- x and y --&amp;quot;);&lt;br /&gt;
      outputArrays(x, y);&lt;br /&gt;
      System.out.println(&amp;quot; -- x and copy of x --&amp;quot;);&lt;br /&gt;
      outputArrays(x, copyArray(x));&lt;br /&gt;
      System.out.println(&amp;quot; -- y and copy of y --&amp;quot;);&lt;br /&gt;
      outputArrays(y, copyArray(y));&lt;br /&gt;
      System.out.println(&amp;quot; -- z and copy of z --&amp;quot;);&lt;br /&gt;
      outputArrays(z, copyArray(z));&lt;br /&gt;
    } catch (final Exception ex) {&lt;br /&gt;
      ex.printStackTrace();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /** &lt;br /&gt;
   * Print out 2 arrays in columnar format.&lt;br /&gt;
   *&lt;br /&gt;
   * @param first The array for the first column.&lt;br /&gt;
   * @param second The array for the second column.&lt;br /&gt;
   *&lt;br /&gt;
   * @throws IllegalArgumentException __UNDOCUMENTED__&lt;br /&gt;
   */&lt;br /&gt;
  public static void outputArrays(final Object first, final Object second) {&lt;br /&gt;
    if (!first.getClass()&lt;br /&gt;
              .isArray()) {&lt;br /&gt;
      throw new IllegalArgumentException(&amp;quot;first is not an array.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    if (!second.getClass()&lt;br /&gt;
               .isArray()) {&lt;br /&gt;
      throw new IllegalArgumentException(&amp;quot;second is not an array.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    final int lengthFirst = Array.getLength(first);&lt;br /&gt;
    final int lengthSecond = Array.getLength(second);&lt;br /&gt;
    final int length = Math.max(lengthFirst, lengthSecond);&lt;br /&gt;
    for (int idx = 0; idx &amp;lt; length; idx++) {&lt;br /&gt;
      System.out.print(&amp;quot;[&amp;quot; + idx + &amp;quot;]\t&amp;quot;);&lt;br /&gt;
      if (idx &amp;lt; lengthFirst) {&lt;br /&gt;
        System.out.print(Array.get(first, idx) + &amp;quot;\t\t&amp;quot;);&lt;br /&gt;
      } else {&lt;br /&gt;
        System.out.print(&amp;quot;\t\t&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
      if (idx &amp;lt; lengthSecond) {&lt;br /&gt;
        System.out.print(Array.get(second, idx) + &amp;quot;\t&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
      System.out.println();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
/* ########## End of File ########## */&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Determining If an Object Is an Array ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    boolean b = &amp;quot;&amp;quot;.getClass().isArray();&lt;br /&gt;
    if (b) {&lt;br /&gt;
      System.out.println(&amp;quot;object is an array&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Getting the Component Type of an Array Object ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    Object o = new int[1][2][3];&lt;br /&gt;
    o.getClass().getComponentType();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Getting the Length and Dimensions of an Array Object ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.lang.reflect.Array;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    Object o = new int[1][2][3];&lt;br /&gt;
    int len = Array.getLength(o); // 1&lt;br /&gt;
    System.out.println(len);&lt;br /&gt;
    int dim = getDim(o); // 3&lt;br /&gt;
    System.out.println(dim);&lt;br /&gt;
  }&lt;br /&gt;
  public static int getDim(Object array) {&lt;br /&gt;
    int dim = 0;&lt;br /&gt;
    Class cls = array.getClass();&lt;br /&gt;
    while (cls.isArray()) {&lt;br /&gt;
      dim++;&lt;br /&gt;
      cls = cls.getComponentType();&lt;br /&gt;
    }&lt;br /&gt;
    return dim;&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Is field an array ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 1995 - 2008 Sun Microsystems, Inc.  All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions of source code must retain the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *     documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Neither the name of Sun Microsystems nor the names of its&lt;br /&gt;
 *     contributors may be used to endorse or promote products derived&lt;br /&gt;
 *     from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS&lt;br /&gt;
 * IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
import static java.lang.System.out;&lt;br /&gt;
import java.lang.reflect.Field;&lt;br /&gt;
public class ArrayFind {&lt;br /&gt;
  public static void main(String... args) {&lt;br /&gt;
    boolean found = false;&lt;br /&gt;
    try {&lt;br /&gt;
      Class&amp;lt;?&amp;gt; cls = Class.forName(args[0]);&lt;br /&gt;
      Field[] flds = cls.getDeclaredFields();&lt;br /&gt;
      for (Field f : flds) {&lt;br /&gt;
        Class&amp;lt;?&amp;gt; c = f.getType();&lt;br /&gt;
        if (c.isArray()) {&lt;br /&gt;
          found = true;&lt;br /&gt;
          out.format(&amp;quot;%s%n&amp;quot; + &amp;quot;           Field: %s%n&amp;quot;&lt;br /&gt;
              + &amp;quot;            Type: %s%n&amp;quot; + &amp;quot;  Component Type: %s%n&amp;quot;, f, f&lt;br /&gt;
              .getName(), c, c.getComponentType());&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
      if (!found) {&lt;br /&gt;
        out.format(&amp;quot;No array fields%n&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
      // production code should handle this exception more gracefully&lt;br /&gt;
    } catch (ClassNotFoundException x) {&lt;br /&gt;
      x.printStackTrace();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Returns the length of the specified array, can deal with Object arrays and with primitive arrays. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*   Copyright 2004 The Apache Software Foundation&lt;br /&gt;
 *&lt;br /&gt;
 *   Licensed under the Apache License, Version 2.0 (the &amp;quot;License&amp;quot;);&lt;br /&gt;
 *   you may not use this file except in compliance with the License.&lt;br /&gt;
 *   You may obtain a copy of the License at&lt;br /&gt;
 *&lt;br /&gt;
 *       http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
 *&lt;br /&gt;
 *   Unless required by applicable law or agreed to in writing, software&lt;br /&gt;
 *   distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; BASIS,&lt;br /&gt;
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;br /&gt;
 *   See the License for the specific language governing permissions and&lt;br /&gt;
 *  limitations under the License.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
import java.lang.reflect.Array;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Operations on arrays, primitive arrays (like &amp;lt;code&amp;gt;int[]&amp;lt;/code&amp;gt;) and&lt;br /&gt;
 * primitive wrapper arrays (like &amp;lt;code&amp;gt;Integer[]&amp;lt;/code&amp;gt;).&lt;br /&gt;
 * &lt;br /&gt;
 * This class tries to handle &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt; input gracefully.&lt;br /&gt;
 * An exception will not be thrown for a &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt;&lt;br /&gt;
 * array input. However, an Object array that contains a &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt;&lt;br /&gt;
 * element may throw an exception. Each method documents its behaviour.&lt;br /&gt;
 *&lt;br /&gt;
 * @author Stephen Colebourne&lt;br /&gt;
 * @author Moritz Petersen&lt;br /&gt;
 * @author &lt;br /&gt;
 * @author Maarten Coene&lt;br /&gt;
 * @since 2.0&lt;br /&gt;
 * @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $&lt;br /&gt;
 */&lt;br /&gt;
public class Main {&lt;br /&gt;
  //-----------------------------------------------------------------------&lt;br /&gt;
  /**&lt;br /&gt;
   * Returns the length of the specified array.&lt;br /&gt;
   * This method can deal with &amp;lt;code&amp;gt;Object&amp;lt;/code&amp;gt; arrays and with primitive arrays.&lt;br /&gt;
   *&lt;br /&gt;
   * If the input array is &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; is returned.&lt;br /&gt;
   *&lt;br /&gt;
   * &amp;lt;pre&amp;gt;&lt;br /&gt;
   * ArrayUtils.getLength(null)            = 0&lt;br /&gt;
   * ArrayUtils.getLength([])              = 0&lt;br /&gt;
   * ArrayUtils.getLength([null])          = 1&lt;br /&gt;
   * ArrayUtils.getLength([true, false])   = 2&lt;br /&gt;
   * ArrayUtils.getLength([1, 2, 3])       = 3&lt;br /&gt;
   * ArrayUtils.getLength([&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;]) = 3&lt;br /&gt;
   * &amp;lt;/pre&amp;gt;&lt;br /&gt;
   *&lt;br /&gt;
   * @param array  the array to retrieve the length from, may be null&lt;br /&gt;
   * @return The length of the array, or &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if the array is &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt;&lt;br /&gt;
   * @throws IllegalArgumentException if the object arguement is not an array.&lt;br /&gt;
   * @since 2.1&lt;br /&gt;
   */&lt;br /&gt;
  public static int getLength(Object array) {&lt;br /&gt;
      if (array == null) {&lt;br /&gt;
          return 0;&lt;br /&gt;
      }&lt;br /&gt;
      return Array.getLength(array);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Use Array.setInt to fill an array ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 1995 - 2008 Sun Microsystems, Inc.  All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions of source code must retain the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *     documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Neither the name of Sun Microsystems nor the names of its&lt;br /&gt;
 *     contributors may be used to endorse or promote products derived&lt;br /&gt;
 *     from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS&lt;br /&gt;
 * IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
import static java.lang.System.err;&lt;br /&gt;
import java.lang.reflect.Array;&lt;br /&gt;
public class ArrayTroubleAgain {&lt;br /&gt;
  public static void main(String... args) {&lt;br /&gt;
    Integer[] ary = new Integer[2];&lt;br /&gt;
    try {&lt;br /&gt;
      Array.setInt(ary, 0, 1); // IllegalArgumentException&lt;br /&gt;
      // production code should handle these exceptions more gracefully&lt;br /&gt;
    } catch (IllegalArgumentException x) {&lt;br /&gt;
      err.format(&amp;quot;Unable to box%n&amp;quot;);&lt;br /&gt;
    } catch (ArrayIndexOutOfBoundsException x) {&lt;br /&gt;
      x.printStackTrace();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Use Array.setShort and Array.setLong ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 1995 - 2008 Sun Microsystems, Inc.  All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions of source code must retain the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *     documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Neither the name of Sun Microsystems nor the names of its&lt;br /&gt;
 *     contributors may be used to endorse or promote products derived&lt;br /&gt;
 *     from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS&lt;br /&gt;
 * IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
import java.lang.reflect.Array;&lt;br /&gt;
public class ArrayTroubleToo {&lt;br /&gt;
  public static void main(String... args) {&lt;br /&gt;
    Object o = new int[2];&lt;br /&gt;
    Array.setShort(o, 0, (short) 2); // widening, succeeds&lt;br /&gt;
    Array.setLong(o, 1, 2L); // narrowing, fails&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>