通用类型的ArrayList的数组列表 [英] Generic type for Arraylist of Arraylists

查看:80
本文介绍了通用类型的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?

在code数组列表的数组列表如下:

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];

和放心地忽略或燮preSS警告。

and safely ignore or suppress the warning.

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

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