2024最新Java集合 ———Java随笔记

总结

谈到面试,其实说白了就是刷题刷题刷题,天天作死的刷。。。。。

为了准备这个“金三银四”的春招,狂刷一个月的题,狂补超多的漏洞知识,像这次美团面试问的算法、数据库、Redis、设计模式等这些题目都是我刷到过的

并且我也将自己刷的题全部整理成了PDF或者Word文档(含详细答案解析)

我的美团offer凉凉了?开发工程师(Java岗)三面结束等通知...

66个Java面试知识点

架构专题(MySQL,Java,Redis,线程,并发,设计模式,Nginx,Linux,框架,微服务等)+大厂面试题详解(百度,阿里,腾讯,华为,迅雷,网易,中兴,北京中软等)

我的美团offer凉凉了?开发工程师(Java岗)三面结束等通知...

算法刷题(PDF)

我的美团offer凉凉了?开发工程师(Java岗)三面结束等通知...

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

需要这份系统化的资料的朋友,可以点击这里获取

  • 既然实现了Cloneable接口,那么代表了它覆盖了函数clone(),证明他是可以被克隆的。

  • 既然实现了java.io.Serializable接口,意味着它支持序列化,能通过序列化进行传输。

  • 我们再看一看AbstractList的继承链和源码:

  • image-20211102231210709.png

  • image-20211102231222779.png

  • 呀,这玩意怎么也实现了List,那为什么我们ArrayList已经继承了AbstractList还要继续实现List呢?

  • 我们自己模拟一个类似这种的实现来看看(此模拟过程参考了其他博主的文章,鉴于不是掘金的文章,这里不贴链接了。)

public class Test {

public static interface MyInterface {

void foo();

}

public static class BaseClass implements MyInterface, Cloneable, Serializable {

@Override

public void foo() {

System.out.println(“BaseClass.foo”);

}

}

public static class Class1 extends BaseClass {

@Override

public void foo() {

super.foo();

System.out.println(“Class1.foo”);

}

}

static class Class2 extends BaseClass implements MyInterface, Cloneable,

Serializable {

@Override

public void foo() {

super.foo();

System.out.println(“Class2.foo”);

}

}

public static void main(String[] args) {

showInterfacesFor(BaseClass.class);

showInterfacesFor(Class1.class);

showInterfacesFor(Class2.class);

}

private static void showInterfacesFor(Class<?> clazz) {

System.out.printf(“%s --> %s\n”, clazz, Arrays.toString(clazz

.getInterfaces()));

}

}

  • 输出结果如下

  • image-20211102231527660.png

  • 从结果可以看出虽然Class1类的父类实现了接口,但是本身并没有再次实现接口,因此通过java.lang.Class直接获取Class1类的接口为空数组。

  • 因此在实现代理的时候就会出现问题。所以可能是设计者就是特意这样设计的嘞?有特别深入了解者,可以解惑下!

  • 唔,这里就点到为止吧,我不知道这个文章需要详细到什么地步?需要贴具体的add和remove的源码讲解嘛?

  • 因此,它适合随机查找和遍历,不适合插入和删除。

四、Vector

  • Vector 与 ArrayList 一样,也是通过数组实现的,不同的是它支持线程的同步,即某一时刻只有一个线程能够写 Vector,避免多线程同时写而引起的不一致性,但实现同步需要很高的花费。因此,访问它比访问 ArrayList 慢。

  • 点击去看一看源码

  • image-20211104194534818.png

  • 继承了AbstractList,实现了List;所以,它是一个队列,支持相关的添加、删除、修改、遍历等功能

  • 实现了RandmoAccess接口,即提供了随机访问功能。RandmoAccess是java中用来被List实现,为List提供快速访问功能的。在Vector中,我们即可以通过元素的序号快速获取元素对象;这就是快速随机访问。

  • 实现了Cloneable接口,即实现clone()函数。它能被克隆。

  • 我们看下Vector的构造函数:

/**

  • Constructs an empty vector with the specified initial capacity and

  • capacity increment.

  • @param initialCapacity the initial capacity of the vector

  • @param capacityIncrement the amount by which the capacity is

  •                          increased when the vector overflows
    
  • @throws IllegalArgumentException if the specified initial capacity

  •     is negative
    

capacity是Vector的默认容量大小,capacityIncrement是每次Vector容量增加时的增量值。

*/

public Vector(int initialCapacity, int capacityIncrement) {

super();

if (initialCapacity < 0)

throw new IllegalArgumentException("Illegal Capacity: "+

initialCapacity);

this.elementData = new Object[initialCapacity];

this.capacityIncrement = capacityIncrement;

}

/**

  • Constructs an empty vector with the specified initial capacity and

  • with its capacity increment equal to zero.

  • @param initialCapacity the initial capacity of the vector

  • @throws IllegalArgumentException if the specified initial capacity

  •     is negative
    

capacity是Vector的默认容量大小。当由于增加数据导致容量增加时,每次容量会增加一倍。

*/

public Vector(int initialCapacity) {

this(initialCapacity, 0);

}

/**

  • Constructs an empty vector so that its internal data array

  • has size {@code 10} and its standard capacity increment is

  • zero.

默认构造函数

*/

public Vector() {

this(10);

}

/**

  • Constructs a vector containing the elements of the specified

  • collection, in the order they are returned by the collection’s

  • iterator.

  • @param c the collection whose elements are to be placed into this

  •   vector
    
  • @throws NullPointerException if the specified collection is null

  • @since 1.2

创建一个包含collection的Vector

*/

public Vector(Collection<? extends E> c) {

elementData = c.toArray();

elementCount = elementData.length;

// c.toArray might (incorrectly) not return Object[] (see 6260652)

if (elementData.getClass() != Object[].class)

elementData = Arrays.copyOf(elementData, elementCount, Object[].class);

}

  • Vector一共有四个构造函数。

  • public Vector(int initialCapacity, int capacityIncrement) :capacity是Vector的默认容量大小,capacityIncrement是每次Vector容量增加时的增量值。

  • public Vector(int initialCapacity) : capacity是Vector的默认容量大小。当由于增加数据导致容量增加时,每次容量会增加一倍。

  • public Vector() : 默认构造函数。

  • public Vector(Collection<? extends E> c) : 创建一个包含collection的Vector。

五、LinkedList

  • LinkedList 是用链表结构存储数据的,很适合数据的动态插入和删除,随机访问和遍历速度比较慢。另外,他还提供了 List 接口中没有定义的方法,专门用于操作表头和表尾元素,可以当作堆栈、队列和双向队列使用。

  • 同样,进去看下源码:

  • image-20211104195104098.png

  • image-20211104195131635.png

  • 首先看下构造函数:

总结

在清楚了各个大厂的面试重点之后,就能很好的提高你刷题以及面试准备的效率,接下来小编也为大家准备了最新的互联网大厂资料。

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

需要这份系统化的资料的朋友,可以点击这里获取

以及面试准备的效率,接下来小编也为大家准备了最新的互联网大厂资料。

[外链图片转存中…(img-gpePgnT4-1715778948221)]

[外链图片转存中…(img-wLF3j3bA-1715778948221)]

[外链图片转存中…(img-MUlnh80V-1715778948221)]

[外链图片转存中…(img-dt28FdHI-1715778948222)]

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

需要这份系统化的资料的朋友,可以点击这里获取

  • 24
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值