zoukankan      html  css  js  c++  java
  • 20191205学习总结

    20191205学习总结

    集合

    数组集合长度

    ArrayList 数组集合数组长度固定,集合长度可变。数组长度: 数组名.length属性集合长度:集合名.size()方法。list.get(下标)通过集合下标来获取数组中的每一个值。

    增删改差

    集合的删除

    针对非int类型e.g.:list.remove("aaa")针对int类型,传入int类型会默认下标。如果删除int类型的值,必须使用封装类。e.g.:List.remove(new Interger(111))

    集合的添加

    list.add(添加值)添加不能超出原来集合的最大长度。ArrayList添加,可以添加重复的数据。

    查找集合中的某个值

    返回指定数据第一次被查找到在集合中的下标。

    list.indexOf(); 从前往后查list:lastIndexOf(); 从后往前查

    查找是否有

    list.contains() 返回布尔值,找到是true,没找到是false。

    判断集合是否为空

    list.isEmpty(); 返回布尔值,找到是true,没找到是false。list.size(0); 返回布尔值,找到是true,没找到是false。

    清空集合所有的元素

    list.clear() 之后size为0。

    ArrayList、Vector、Stack的区别

    ArrayList:没有考虑线程问题,在一些算法上做了优化,速度更快,效率更高。Vector:线程是安全的(已经不用了)。Stack:线程是安全的(已经不用了)。

    这三个底层都是数组的实现。

    链表LinkList

    LinkList与ArrayList的区别

    1.ArrayList底层是数组的实现,LinkedList底层是链表的实现。1.1 在java中链表就是自己实现了一个类,在类中记录了前一个和后一个的地址。每次查找都需要找到前一个或者后一个才能往前或者往后找到。2.ArrayList查找速度快,但是删除和插入的速度慢。3.LinkedList删除和插入的速度快,但是查询速度较慢。4.LinkedList有自己独有的addFirst addLast removeLast removeFirst的方法。

    List接口下的特点

    1.都是有序的(按照添加的顺序获取)。2.都有下标。3.可以重复。

    增强for循环(foreach循环)遍历集合

    格式:for(元素的数据类型 变量 : Collection集合or数组){

    }

    for(Object obj : set) {
    System.out.println(obj);
    }

    迭代器

    Iterator it = set.iterator();
    while(it.hasNext()) {
    Object obj = it.next();
    System.out.println(obj);
    }

    set接口下的集合特点

    1.没有下标2.无序的3.不能重复(覆盖)

    List接口和set接口的区别

    1.有无下标。2.有无序。3.能否重复。

    泛型

    集合需申明泛型,基本数据类型的泛型集合必须使用包装类。

    TreeSet

    TreeSet用的很少,是有序的TreeSet要求放入进去的对象必须实现Comparable接口。并且实现Comparable接口的CompareTo方法。

    Set对List的转换

    List < > lists = new ArrayList<>();

    Collection和Collections的区别

    collection:接口。collections:实现类或者工具类。

    Comparable和Comparator的区别

    Comparable:在java.lang下,必须要实现comparaTo()方法,一个参数。一般用实体类去直接实现comparable接口。Comparator:在java.util下,必须实现compare()方法,两个参数。需要另外一个类或内部类来实现这个接口。

  • 相关阅读:
    cmd utf-8 just run:CHCP 65001
    PHP5已注册的hash函数
    php扩展开发笔记1
    configure: error: cannot find neither zip nor jar, cannot continue
    configure: error: cannot compute suffix of object files: cannot compile
    configure: error: I suspect your system does not have 32-bit developement libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to b
    /usr/bin/ld: crt1.o: No such file: No such file or directory
    近两周工作总结
    我觉得好用的VS扩展(不定期更新)
    vmware虚拟机无法ping通宿主机,但宿主机可以ping通虚拟机
  • 原文地址:https://www.cnblogs.com/Wardenclyffe/p/11995924.html
Copyright © 2011-2022 走看看