访问列表<列表<字符串>>使用这个关键字 [英] Access List<List<String>> using this keyword

查看:95
本文介绍了访问列表<列表<字符串>>使用这个关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我将值存储到列表A,列表B&中.通过for循环列出C. 列表A,B,C值通过以下方式添加:

Lets assume that I store values to List A, List B & List C through for loop. List A,B,C values is added by the following way:

for (int j = 0; j <5; j++) 
{
   list_A.add("Value"+i);
   list_B.add("Value"+i);
   list_C.add("Value"+i);
}

要通过以下方式使用我使用 this 关键字的方法访问列表:

To access the List out of the method I'm using this keyword by the following way:

private CharSequence ListA[]; // declaration    
this.ListA= list_A.toArray(new CharSequence[list_A.size()]); //accessing with this keyword

现在,我通过以下方式将所有这些列表添加到另一个列表中

Now I am adding all these list to another List by the following way

List<List<String>> finallist = new ArrayList<>();
finallist .add(list_A);
finallist .add(list_B);
finallist .add(list_C);

我进行了一些搜索,但找不到如何声明和访问List<列表<字符串>>使用此关键字?

I did some searching but I couldn't find how to declare and access List< List< String>> using this keyword?

注意:这是我问过的问题的实际修改,

Note: It is the actual modification of the question that I have asked here. As I couldn't get any answer, I thought I could make it bit simple and have raised the question here.

推荐答案

访问另一类中的一个变量时,您可以执行以下操作:

When accessing a variable of one class in another, you could do something like this:

public static final List<String> list_A = new ArrayList<>();
static{
    for (int j = 0; j <5; j++) 
    {
        list_A.add("Value"+i);
    }
}

片段类

CharSequence ListA[];
ListA = MainClass.list_A.toArray(new CharSequence[MainClass.list_A.size()]);

我建议在list_A

这篇关于访问列表&lt;列表&lt;字符串&gt;&gt;使用这个关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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