KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > util > ArrayUtil


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.jpivot.util;
14
15 import java.lang.reflect.Array JavaDoc;
16
17 public class ArrayUtil {
18   
19   /**
20    * copy an array to an arry of its natural type
21    * @param array input
22    * @return array of natural type
23    */

24   public static Object JavaDoc naturalCast(Object JavaDoc[] array) {
25     Class JavaDoc clazz = array[0].getClass();
26     Object JavaDoc[] newArray = (Object JavaDoc[]) Array.newInstance(clazz, array.length);
27     for (int i = 0; i < newArray.length; i++) {
28       newArray[i] = array[i];
29     }
30     return newArray;
31   }
32
33 } // ArrayUtil
34
Popular Tags