List子接口
发布日期:2021-04-30 21:05:59 浏览次数:104 分类:精选文章

本文共 2280 字,大约阅读时间需要 7 分钟。

List??????????

List???Java?????????????????????????????????????????????????????????Java??????List??????????????

List?????

List??????????????????????List????????

  • ?????????????????????
  • ??????????????
  • ???????????????????
  • List???????

    List????????????????????????????????????????????

  • ????

    • void add(int index, Object o)
    • ????????????????????????
  • ??????

    • boolean addAll(int index, Collection c)
    • ????????????????
  • ????

    • Object get(int index)
    • ?????????
  • ?????

    • List subList(int fromIndex, int toIndex)
    • ???fromIndex?toIndex??????
  • List???????

    ???????List????????

    // ????
    List list = new ArrayList();
    // ????
    list.add("??");
    list.add("??");
    list.add(0, "OPPO");
    // ??????
    System.out.println(list.size()); // 3
    // ??????
    System.out.println(list.toString()); // [OPPO, ??, ??]
    // ????
    // ??????for??
    for (int i = 0; i < list.size(); i++) {
    System.out.println(list.get(i)); // OPPO, ??, ??
    }
    // ??????for??
    for (Object obj : list) {
    System.out.println(obj); // OPPO, ??, ??
    }
    // ?????????
    Iterator it = list.iterator();
    while (it.hasNext()) {
    System.out.println(it.next()); // OPPO, ??, ??
    }
    // ???????????
    ListIterator lit = list.listIterator();
    // ??????
    while (lit.hasNext()) {
    System.out.println(lit.nextIndex() + ":" + lit.next());
    // 0:OPPO, 1:??, 2:??
    }
    // ??????
    while (lit.hasPrevious()) {
    System.out.println(lit.previousIndex() + ":" + lit.previous());
    // 2:??, 1:??, 0:OPPO
    }
    // ????????
    System.out.println(list.contains("??")); // true
    System.out.println(list.isEmpty()); // false
    // ??????
    System.out.println(list.indexOf("??")); // 1
    // ????
    System.out.println(list.remove(0)); // true
    System.out.println(list.toString()); // [??, ??]
    // ??????????
    List list2 = new ArrayList();
    list2.add(10);
    list2.add(20);
    list2.add(30);
    list2.add(40);
    // ??????
    System.out.println(list2.remove(20)); // true
    System.out.println(list2.toString()); // [10, 30, 40]
    // ?????
    List subList = list2.subList(1, 3);
    System.out.println(list2.toString()); // [30, 40]

    ??????

    ???????????List????????????????????????????????????????????

  • ????

    • ??remove(int index)???????????
    • ?????remove(Object o)?????????
  • ??????

    • ??indexOf(Object o)???????????
  • ????????

    • ??contains(Object o)??????????
  • ?????

    • ??subList(int fromIndex, int toIndex)???????
  • ??????List??????????????????????????Java????????????

    上一篇:在IDEA中使用maven遇到的问题
    下一篇:JDK、JRE、JVM三者之间的关系

    发表评论

    最新留言

    很好
    [***.229.124.182]2026年06月23日 04时35分26秒