zoukankan      html  css  js  c++  java
  • 继承(三)

    关于hashCode

    hashCode的产生原则:

    hashCode的改进过程:

    更优的做法:

    equals方法与hashCode的联系:

    数组的hashCode:

    toString方法

    对象调用这个的话,返回表示对象值的字符串

     数组的toString方法:

     String的equal

    hashCode乘以的数字是啥意思

    两个对象 == 的时候调用equals吗

    Objects.hashCode(a)的时候涉及多态了么

    ArrayList操作:

    import java.io.Console;
    import java.time.*;
    import java.util.*;
    
    class Employee{
        private String name;
        private int age;
        public Employee(String a_name, int a_age) {
            name = a_name;
            age = a_age;
        }    
    }
    
    public class Test{
        public static void main(String[] args) {
            
            ArrayList<Employee> staff = new ArrayList<>(100);
            // staff.ensureCapacity(100); 作用与上一句相同
            
            // 获取存入元素的数量
            int a = staff.size();
            
            Employee ab = new Employee("ab", 1);
            Employee bc = new Employee("bc", 2);
            
            // add 也可用于插入元素
            staff.add(ab);
            staff.set(0, bc);
            Employee gt = staff.get(0);
            
            staff.remove(0);
            // to array
            Employee[] as = new Employee[staff.size()];
            staff.toArray(as);
            
            // 确定 staff 的大小不会变了,将存储空间的大小调整为当前元素所需要的存储空间数目,gc回收多余的存储空间
            // 在这之后再添加新元素的话需要花时间再次移动存储块,开销较大
            staff.trimToSize();
        }
    }

    ArrayList和数组指定大小的不同:

     ArrayLIst与泛型???

    对象包装器

    不可变的,一旦构造了包装器,就不允许更改包装在其中的值

    对象包装器类是final的,不允许派生子类

    关于操作效率的问题:

    什么是自动装箱?

    自动拆箱:

    关于包装对象的相等性不确定的问题:

    顺序和执行问题:

    可以将某些基本方法放置在包装器中,比如静态方法:
    int x = Integer.parseInt(s);

    参数数量可变:

  • 相关阅读:
    LeetCode Count of Range Sum
    LeetCode 158. Read N Characters Given Read4 II
    LeetCode 157. Read N Characters Given Read4
    LeetCode 317. Shortest Distance from All Buildings
    LeetCode Smallest Rectangle Enclosing Black Pixels
    LeetCode 315. Count of Smaller Numbers After Self
    LeetCode 332. Reconstruct Itinerary
    LeetCode 310. Minimum Height Trees
    LeetCode 163. Missing Ranges
    LeetCode Verify Preorder Serialization of a Binary Tree
  • 原文地址:https://www.cnblogs.com/geeklove01/p/10033757.html
Copyright © 2011-2022 走看看