数组的常用情况前后台

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/past__time/article/details/82216605

1.如何new一个数组

String[] a = new String[3];
String[] b = {"a","b","c"};
String[] c = new String[]{"a","b","c"};

2.向空数组中添加数据

定义一个数组
String[] s = new String[3];
赋值
  s[0] = "1";
  s[1] = "asfa";
  s[2] = "5555";
数组长度是固定的,不能增加或删除。

3.一个list的数组泛型,以及遍历

public static void main(String[] args){
    List<String []> list = new ArrayList<String []>();
    String [] s = {"1","2","3","4","5"};
    String [] a = {"6","7","8"};
    String in = "";
    list.add(s);
    list.add(a);
    for (int i = 0;i < list.size();i ++){
        for (int j = 0; j < list.get(i).length; j ++){
                in = list.get(i)[j];
            System.out.println(in);
        }
    }
}

4.在页面foreach循环list里面的数组

<tr>
    <c:forEach begin="0" end="0" items="${titleList}" var="tit">
        <c:forEach items="${tit}" var="t">
            <td>${t}</td>
        </c:forEach>
    </c:forEach>
</tr>

猜你喜欢

转载自blog.csdn.net/past__time/article/details/82216605