提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
创建一个以单个对象作为组件的数组。
//package com.nowjava;/** from 时 代 J a v a 公 众 号 - N o w J a v a . c o m**/ import java.lang.reflect.Array; public class Main { public static void main(String[] argv) throws Exception { Object object = "nowjava.com"; System.out.println(convertToArray(object)); } /** * Creates an array with a single object as component. * If the specified object is an array, it will be returned * unchanged. Otherwise an array with the specified object * as the single element will be returned. * @param object the object * @return the corresponding array */ public static Object convertToArray(Object object) { if (object.getClass().isArray())