JAVA 习题, 高手进

Q6:Completetheoutputwhentheex06()methodisexecuted:privatevoidex06(){ArrayListmyList=c... Q6: Complete the output when the ex06() method is executed:

private void ex06() {
ArrayList myList = createArrayList();
System.out.println( "1. LIST IS: " + myList );
Object item1 = myList.get(0);
System.out.println("2. Element at position 2 " + myList.get(2));
int pos2 = myList.indexOf( new Point(3,3) );
if( pos2 > -1 ) {
myList.remove(pos2);
}
Point item3 = new Point(3, 3);
myList.add(1, item3);
myList.remove(1);

System.out.print("3. ");
for( int i=0; i<myList.size(); i++ ) {
String item = (myList.get(i)).toString();
if (item.length() == 3 ) {
System.out.print(item.toString() + " ");
}
}
System.out.println();
System.out.println("4. LIST IS: " + myList );
}
private ArrayList createArrayList() {
ArrayList myList = new ArrayList();
myList.add( new String("Uno") );
myList.add( new String("Due") );
myList.add( new Point(3, 3) );
myList.add( new Integer(456) );
myList.add( new Character('c') );
myList.add( new String("Tre") );
myList.add( new Point(3, 3) );
return myList;
}

1. LIST IS: [Uno, Due, java.awt.Point[x=3,y=3], 456, c, Tre, java.awt.Point[x=3,y=3]]
2.
3.
4. LIST IS: [ ]

这是道填空题:
帮我解释下, 谢谢
展开
 我来答
junjie0251
2009-10-26 · 超过21用户采纳过TA的回答
知道答主
回答量:35
采纳率:0%
帮助的人:0
展开全部
  运行结果如下:
  1. LIST IS: [Uno, Due, java.awt.Point[x=3,y=3], 456, c, Tre, java.awt.Point[x=3,y=3]]
  2. Element at position 2 java.awt.Point[x=3,y=3]
  3. Uno Due 456 Tre
  4. LIST IS: [Uno, Due, 456, c, Tre, java.awt.Point[x=3,y=3]]

  解释:
  1.定义了方法createArrayList() :该方法中创建了一个ArrayList实例,对其复制(依次地添加元素),并返回该实例;
  2.System.out.println( "1. LIST IS: " + myList ),打印“1.LIST:”以及ArrayList类型的myList实例;
  3.System.out.println("2. Element at position 2 " + myList.get(2));
  打印myList中下标为2的元素;
  4.int pos2 = myList.indexOf( new Point(3,3) );
  if( pos2 > -1 ) {
  myList.remove(pos2);
  }
  Point item3 = new Point(3, 3);
  myList.add(1, item3);
  myList.remove(1);
  获取元素new Point(3,3)的下标,若存在,则将其删除,并在myList下标为1的位置中插入元素item3;在删除下标为1的元素。
  5.for( int i=0; i<myList.size(); i++ ) {
  String item = (myList.get(i)).toString();
  if (item.length() == 3 ) {
  System.out.print(item.toString() + " ");
  }
  }
  遍历myList,并打印出其长度为3的元素;
  6.System.out.println("4. LIST IS: " + myList );
  打印整个myList
Christ_earl
2009-10-26 · TA获得超过1245个赞
知道小有建树答主
回答量:239
采纳率:0%
帮助的人:0
展开全部
1. LIST IS: [Uno, Due, java.awt.Point[x=3,y=3], 456, c, Tre, java.awt.Point[x=3,y=3]]

2. Element at position 2 java.awt.Point[x=3,y=3]

3. Uno Due 456 Tre

4. LIST IS: [Uno, Due, 456, c, Tre, java.awt.Point[x=3,y=3]]
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
怼怼喵喵3L
2009-10-26 · 超过23用户采纳过TA的回答
知道答主
回答量:113
采纳率:0%
帮助的人:0
展开全部
1. LIST IS: [Uno, Due, java.awt.Point[x=3,y=3], 456, c, Tre, java.awt.Point[x=3,y=3]]
2. Element at position 2 java.awt.Point[x=3,y=3]
3. Uno Due 456 Tre
4. LIST IS: [Uno, Due, 456, c, Tre, java.awt.Point[x=3,y=3]]
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
20...5@qq.com
2009-10-26 · TA获得超过390个赞
知道答主
回答量:250
采纳率:0%
帮助的人:298万
展开全部
1. LIST IS: [Uno, Due, java.awt.Point[x=3,y=3], 456, c, Tre, java.awt.Point[x=3,y=3]]
2. Element at position 2 java.awt.Point[x=3,y=3]
3. Uno Due 456 Tre
4. LIST IS: [Uno, Due, 456, c, Tre, java.awt.Point[x=3,y=3]]
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zhangrun_gz
2009-10-26 · TA获得超过675个赞
知道小有建树答主
回答量:793
采纳率:0%
帮助的人:475万
展开全部
2. Element at position 2 java.awt.Point[x=3,y=3]

3. Uno Due 456 Tre
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
朴素守中
2009-10-26 · TA获得超过240个赞
知道小有建树答主
回答量:216
采纳率:81%
帮助的人:84.7万
展开全部
1. LIST IS: [Uno, Due, java.awt.Point[x=3,y=3], 456, c, Tre, java.awt.Point[x=3,y=3]]
输出整个列表。
2. Element at position 2 java.awt.Point[x=3,y=3]
返回此列表中索引为2的元素.也就是列表中的第3个元素。而第三个元素就是
java.awt.Point[x=3,y=3]
3. Uno Due 456 Tre
输出列表中字符串长度为3的字符串
4. LIST IS: [Uno, Due, 456, c, Tre, java.awt.Point[x=3,y=3]]
因为 int pos2 = myList.indexOf( new Point(3,3) );
if( pos2 > -1 ) {
myList.remove(pos2);
}
把第三个元素给removed掉了。所以结果就这样了。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(5)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式