zoukankan      html  css  js  c++  java
  • 集合框架

    package test;

    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.ListIterator;
    import java.util.Vector;

    public class MyList implements Comparable<MyList>{
    public static void main(String[] args) {
    List<Integer> s = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
    s.add(i);// 增加一个数据
    }
    s.remove(5);// 删除数据
    s.set(1, 10);// 修改数据
    for (int i = 0; i < s.size(); i++) {
    System.out.print(s.get(i) + ",");// s.get(i)取得数组中的第个值
    }
    System.out.println();
    System.out.println("*************************************");
    List<Integer> s1 = new LinkedList<>();
    for (int i = 0; i < 10; i++) {
    s1.add(i);// 增加一个数据
    }
    s1.remove(5);// 删除数据
    s1.set(1, 10);// 修改数据
    Iterator<Integer> l = s1.iterator();
    while (l.hasNext()) {
    Integer l3 = l.next();
    System.out.print(l3 + ",");
    }
    System.out.println();
    System.out.println("*************************************");
    List<Integer> s2 = new Vector<>();
    for (int i = 0; i < 10; i++) {
    s2.add(i);// 增加一个数据
    }
    s2.remove(5);// 删除数据
    s2.set(1, 10);// 修改数据

    ListIterator<Integer> l1 = s2.listIterator(6);
    while (l1.hasPrevious()) {
    Integer l2 = l1.previous();
    System.out.print(l2 + ",");

    Collections.sort(s); //集合排序
    // Arrays.sort(s);-------数组排序
    }

    @Override//排序方法
    public int compareTo(MyList o) {
    return 0;
    }
    }

     Set

    package test;

    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.Set;
    import java.util.TreeSet;

    public class MySet {
    public static void main(String[] args) {
    Set<Integer> s= new HashSet<>();
    for (int i = 0; i < 10; i++) {
    s.add(i); //增加
    }
    s.remove(0);//删除
    for (Integer integer : s) {
    System.out.print(integer+",");//打印
    }
    s.remove(1);//修改先删后加
    s.add(1);

    System.out.println();
    System.out.println("*****************");

    Set<Integer> s1=new TreeSet<>();
    for (int i = 0; i < 10; i++) {
    s1.add(i); //增加
    }
    s1.remove(0);//删除
    Iterator<Integer> s2 = s1.iterator();
    while (s2.hasNext()) {
    Integer integer = (Integer) s2.next();
    System.out.print(integer+",");
    }
    s1.remove(1);//修改先删后加
    s1.add(1);
    }
    }

  • 相关阅读:
    mongo批量删除js示例
    Mongo压测介绍
    线性代数学习笔记(1)--二维向量点积本质(仅供自己理解)
    墨菲定律的正确解读
    spring cloud 2020.0.1踩坑记录-bootstrap不生效等
    记一次网络质量原因导致接口调用超时的调查过程
    .NET Debugging Demos Lab 2: Crash
    .NET Debugging Demos Lab 3: Memory
    Hang caused by GC
    .NET Debugging Demos Lab 4: High CPU hang
  • 原文地址:https://www.cnblogs.com/joyous-day/p/6513810.html
Copyright © 2011-2022 走看看