public class test {
public test() {
}
public static void main(String[] args) {
ArrayList arratlist = new ArrayList();
ArrayList thearratlist = new ArrayList();
for (int i=0;i<5;i++){
arratlist.add(Integer.toString(i));
}
thearratlist.add(arratlist);
}
}
public test() {
}
public static void main(String[] args) {
ArrayList arratlist = new ArrayList();
ArrayList thearratlist = new ArrayList();
for (int i=0;i<5;i++){
arratlist.add(Integer.toString(i));
}
thearratlist.add(arratlist);
}
}
解决方案 »
- 求教:类方法访问限制,“朋友”才可访问
- 软件企业对学历要求严格吗
- 终于找到广播和接收自定义事件的资料了,高兴才分享
- 关于创建对像以自身作为参数调用构造方法的理解
- 请教JFrame 和 JPanel 的关系?
- 【SWT】 如何设置 JFace 的 Dialog 的大小?
- java web server是什么啊 哪里有的下载
- 高手来帮我看看出了什么问题,解决马上结帖。
- 谁说java没指针,我觉得全是指针才对
- 我想编写收发短消息的程序,怎样得到相关的方法(如何和移动或联通连接)?谢谢
- !!!我现在j2se部分学的差不多了,请高手指点我要向哪方面学习
- !!!我写的一个在搜索硬盘上的文件的软件为什么在搜索ntfs格式的时候会出现nullpoint错误,而fat的不会
你在第一个程序中arratlist是一个局部变量,对于thearratlist 是不可见的
public test() {
}
public static void main(String[] args) {
ArrayList thearratlist = new ArrayList();
for (int i=0;i<5;i++){
ArrayList arratlist = new ArrayList();
arratlist.add(Integer.toString(i));
}
thearratlist.add(arratlist);
}
}
这里arratlist只在循环内有效。可以这样写
public class test {
public test() {
}
public static void main(String[] args) {
ArrayList thearratlist = new ArrayList();
ArrayList arratlist = null;
for (int i=0;i<5;i++){
arratlist = new ArrayList();
arratlist.add(Integer.toString(i));
}
thearratlist.add(arratlist);
}
}这样就没有问题了。
每次变成新定义一个了arraylist了呵呵。不好意思。写错了。