zoukankan      html  css  js  c++  java
  • Document

    题目:创建一个只能容纳String对象名为names的Arraylist集合,按顺序向集合中添加5个字符串对象。对集合进行遍历,打印出集合中每个元素的位置与内容。首先打印出集合的大小,然后删除集合中的第三个元素,并显示删除的内容,删除之后,再次显示现在集合第三个元素的内容,之后再打印出集合的大小。 

    其实,这个东西我只实现了部分功能,等有空在完善吧,最主要是不知道那个函数名字,有点尴尬了

    代码运行效果:

    你们想要的代码来了,哈哈----------------------------

    代码:

    /****
    * 创建一个只能容纳String对象名为names的Arraylist集合,
    * 按顺序向集合中添加5个字符串对象。对集合进行遍历,打印出集合中每个元素的位置与内容。
    * 首先打印出集合的大小,然后删除集合中的第三个元素,并显示删除的内容,删除之后,
    * 再次显示现在集合第三个元素的内容,之后再打印出集合的大小。
    * @author yanlong
    * 2017/5/9
    */
    import java.util.ArrayList;
    import java.util.Iterator;
    //import java.util.*;

    public class test2 {
    public static void main(String[] args) {
    // 创建集合对象
    ArrayList<String> array = new ArrayList<String>();

    // 创建并添加元素
    array.add("chen");
    array.add("yan");
    array.add("long");
    array.add("ni");
    array.add("hao");

    // 遍历集合
    // 迭代器
    Iterator<String> it = array.iterator();
    while (it.hasNext()) {
    String s = it.next();
    System.out.println(s);
    }
    System.out.println("------------------");
    System.out.println("------ 我很好-------");
    System.out.println("------------------");

    array.remove(3);
    Iterator<String> it1 = array.iterator();
    //array.remove(3);
    while (it1.hasNext()) {
    String s1 = it1.next();
    System.out.println(s1);
    }
    }

    }

  • 相关阅读:
    python 函数嵌套
    python 函数对象
    python 函数参数
    python 连接MySQL报错及解决方案
    解决 No module named pip
    python 文件处理
    python
    python 元祖
    python 读取域名信息
    ubuntu 配置网卡,DNS, iptables
  • 原文地址:https://www.cnblogs.com/chenyanlong/p/6832969.html
Copyright © 2011-2022 走看看