创建多个对象类型的ArrayList? [英] Create an arraylist with multiple object types?

查看:360
本文介绍了创建多个对象类型的ArrayList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何创建一个整数和字符串输入类型的一个ArrayList?如果我创建的
     列表与LT;整数GT;部分=新的ArrayList<整数GT;();
这将是一个整数ArrayList类型。
如果我创建的
    列表与LT;弦乐>部分=新的ArrayList<串GT;(); ,将字符串类型。
如何建立可采取两种int和字符串输入类型的ArrayList?
谢谢

How do i create an arraylist with integer and string input types? If i create as List<Integer> sections = new ArrayList <Integer>(); that will be a Integer type arrayList. If i create as List<String> sections = new ArrayList <String>(); that will be String type. How can i create an arraylist which can take both int and String input types? Thank you

推荐答案

您可以把它想:

List<Object> sections = new ArrayList <Object>();

推荐)另一种可能的解决方案是使一个自定义的模型类有两个参数一个整型等字符串。然后使用的ArrayList 的对象。

(Recommended) Another possible solution would be to make a custom model class with two parameters one Integer and other String. Then using an ArrayList of that object.

这篇关于创建多个对象类型的ArrayList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆