首页 > 其他 > 详细

如何在ArrayList<Integer>中添加String类型数据

时间:2015-05-28 18:09:04      阅读:315      评论:0      收藏:0      [点我收藏+]

 黑马入学测试题:

ArrayList list = new ArrayList();

在这个泛型为Integer的ArrayList中存放一个String类型的对象。

package itheima;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

/**
 * 在这个泛型为Integer的ArrayList中存放一个String类型的对象。
 * @author Administrator
 *
 */
public class AddStringToArrayList {
	//用反射机制
	public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		ArrayList<Integer> list=new ArrayList<Integer>();
		Method method = list.getClass().getMethod("add", Object.class);
		method.invoke(list, "i am a String");
		System.out.println(list);
	}
}


如何在ArrayList<Integer>中添加String类型数据

原文:http://blog.csdn.net/u014010769/article/details/46125147

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!