Arraylists 的 Arraylist 的通用类型 [英] Generic type for Arraylist of Arraylists

查看:30
本文介绍了Arraylists 的 Arraylist 的通用类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在普通的数组列表初始化中,我们以前定义泛型类型如下,

In normal array list initialization, We used to define generic type as follows,

List<String> list1 = new ArrayList<String>();

但是对于ArrayLists的ArrayList,我们如何定义它的泛型类型?

But in case of ArrayList of ArrayLists, How can we define its generic type?

数组列表的数组列表代码如下:

The code for array list of array lists is as follows:

ArrayList[] arr=new ArrayList[n];
 for(int i=0;i<n;i++)
 {
 arr[i]=new ArrayList();
 } 

分享语法,如果有人知道的话..!

Just share the syntax, if anybody have idea about it..!

推荐答案

你可以简单地做

List<List<String>> l = new ArrayList<List<String>>();

如果你需要一个列表数组,你可以这样做

If you need an array of Lists, you can do

List<String>[] l = new List[n];

并安全地忽略或取消警告.

and safely ignore or suppress the warning.

这篇关于Arraylists 的 Arraylist 的通用类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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