ArrayList,LinkedList,HashTable三者是JAVA中的三种常见的数据结构,当然它们的性能有不同的差异,比如数据查找速度,增加或删除数据的速度,内存空间占用等等,这将在下篇博客中体现,这篇博客只是大致应用数据结构知识来自己实现三种数据结构的基本功能,包含一些简单的增查改删功能。
ArrayList:
public class ArrayList { private int counts; //数组实际填充大小 private int stepcount; //数组将溢出时的扩充步长 Object[] data =new Object[10]; //默认数组长度为10 //无参的构造方法,默认扩充步长为100 public ArrayList(){ stepcount=100; } //带初始数组长度与扩充步长的构造方法 public ArrayList(int initlen,int stepcount){ data=new Object[initlen]; this.stepcount=stepcount; } //给数组添加新数据 public void add(Object obj){ if(counts>=data.length){ //判断有无溢出,溢出则增加数组长度stepcount,并将原数组数据放入新数组 Object[] data2=new Object[data.length+stepcount]; for(int i=0;i<data.length;i++){ data2[i]=data[i]; } data=data2; } data[counts++]=obj; } //获得指定数组位置的内容 public Object get(int index){ if(index<0||index>data.length){ System.out.println("超出数组限定范围"); return null; } return data[index]; }; //删除指定位置的元素 public void remove(int index){ Object[] data2 = new Object[data.length-1]; for (int i=0;i<index;i++){ data2[i]=data[i]; } for (int i=index+1;i<data.length;i++){ data2[i-1]=data[i]; } data=data2; Object obj =data[index]; } //获得数组大小 public int size(){ return counts; } //在指定位置插入元素 public void insert(Object obj,int index){ Object[] data2 =new Object[data.length+1]; //新建一数组才可从数组中间插入,此时新数组长度需至少加一 for(int i=0;i<index;i++){ data2[i]=data[i]; } data2[index]=obj; for(int i=index+1;i<data2.length;i++){ data2[i]=data[i-1]; } data=data2; } }
LinkedList:
public class MyLinkList implements List { //声明根节点 private Node root=null private Node tail,tempt; private int total; //给链表添加元素 public void add(Object obj) { Node newnode =new Node(); if (root==null){ newnode.data=obj; root=newnode; tail=newnode; } else{ tail.next=newnode; newnode.data=obj; tail=newnode; } total++; } //获取链表指定位置元素(为便于习惯,默认从一开始) public Object get(int index) { if(index==0){ return null; } if(index-1==0){ return root.data; } else { tempt=root; for(int i=1;i<index;i++){ tempt=tempt.next; } return tempt.data; } } //删除某指定链表元素 public void remove(int index) { if(index-1==0){ root=root.next; } else { tempt=root; for(int i=1;i<index-1;i++){ tempt=tempt.next; } tempt.next=tempt.next.next; } total--; } //获得链表的大小 public int size() { return total; } //给链表指定位置插入某元素 public void insert(Object obj, int index) { Node insertNode =new Node(); insertNode.data=obj; if(index-1==0){ insertNode.next=root; root=insertNode; } else { tempt=root; for(int i=1;i<index-1;i++){ tempt=tempt.next; } insertNode.next=tempt.next; tempt.next=insertNode; } total++; } //该链表内部类实现对Node的定义 class Node{ Object data; Node next; Node(Node next,Object data){ this.next=next; this.data=data; } } }HashTable:
相关推荐
线性数据结构动态数组(ArrayList) 链表(LinkedList) 单向链表 双向链表 循环链表 静态链表 栈(Stack) 队列(Queue) 双端队列(Deque) 循环队列 哈希表(HashTable) 树形数据结构 二叉树(BinaryTree)、...
14、JAVA集合框架之list接口、LinkedList类、ArrayList类、Vector类 15、JAVA集合框架之Set接口、HashSet类、TreeSet类 16、JAVA集合框架之Map接口、HashMap类、Trelap类、Hashtable类 17、JAVA异常Exception 18...
Java面试题10.ArrayList 和LinkedList的区别 Java面试题11.HashMap和HashTable的区别 Java面试题12.实现一个拷贝文件的工具类要使用字节流还是字符串 Java面试题13.线程的的实现方式?怎么启动线程?怎么区分线程? ...
Java集合详解1:一文读懂ArrayList,Vector与Stack使用方法和实现原理 Java集合详解2:Queue和LinkedList Java集合详解3:Iterator,fail-fast机制与比较器 Java集合详解4:HashMap和HashTable Java集合详解5:深入...
数据结构 北卡罗来纳科学与数学学院在 CS410(数据结构)中创建的... 实现IList.java接口的 LinkedList 数据结构。 DuhHashTable.java 实现IList.java接口的 HashTable 数据结构。 节点.java 在DuhLinkedList.java
数据结构Java 主要数据结构——java中的简单实现如何使用集合:-> JDK(Java集合)-> Guava(谷歌)-> Commons-collections(Apache) 主要抽象数据结构——ADS列表(ArrayList、LinkedList、Vector)栈(FIFO)队列...
就是一些通用java集合知识点整理,ArrayList LinkedList,HashMap,HashTable ,ConcurrentHashMap,HashSet,LinkedHashSet类通过线程安全否: 底层: 初始值: 扩容 : 区别(对比优势) 图解
1. java.util.*包的UML结构图。 Collection List LinkedList ArrayList Vector Stack Set HashSet Map HashMap Dictionary Hashtable Comparetor 2. Vector和ArrayList、LinkedList区别? Hashtable 和 HashMap之间...
Java集合详解:一文读懂ArrayList,Vector与Stack使用方法和实现原理 Java集合详解:Queue和LinkedList Java集合详解:迭代器,快速失败机制与比较器 Java集合详解:HashMap和HashTable Java集合详解:深入理解...
ArrayList Vector LinkedList 类Stack HashSet TreeSet LinkedHashSet 类 PriorityQueue HashMap TreeMap 类 LinkedHashMap 类 Hashtable 类IdentityHashMap 类WeakHashMap 类 Collections 类集合实现类特征图 泛形 ...
│ Java面试题10.ArrayList LinkedList.mp4 │ Java面试题11.HashMap和HashTable的区别.mp4 │ Java面试题12.实现一个拷贝文件的类使用字节流还是字符串.mp4 │ Java面试题13.线程的实现方式 怎么启动线程怎么区分...
• 熟悉常用集合数据结构(数组、Hashmap、ConcurrentHashMap、HashTable、ArrayList、Vetor、LinkedList、HashSet、TreeSet、LinkedHashSet),了解AVL、RBtree、B/B+树、跳表 • 熟悉常见异常分类以及处理,熟悉反射...
java为数据结构中的列表定义了一个接口类java.util.list同时提供了3个实现类,分别是ArrayList、Vector、LinkedList使用; 生成不重复的随机数序列;列表、集合与数组的互相转换;java为数据结构中的映射定义一个接口...
1. 分别使用Vector、Hashtable、Stack,ArrayList、LinkedList和HashSet作为容器类,实现以下要求: (1) 向容器中添加1,000,000个随机整数。 (2) 遍历容器中的所有元素。 (3) 随机产生100,000个整数,在容器中查找...
java集合在日常开发中经常用到,对基础的掌握尤其重要,其中List,Set,Map的作用以及使用的场景和分类描述,其中Arraylist 与 LinkedList 区别,HashSet与TreeSet与LinkedHashSet对⽐,LinkedHashMap和HashMap,...
25. ArrayList 和 LinkedList 的区别是什么? 26. 如何实现数组和 List 之间的转换? 27. ArrayList 和 Vector 的区别是什么? 28. Array 和 ArrayList 有何区别? 29. 在 Queue 中 poll()和 remove()有什么区别? ...
Java面试题10.ArrayList 和LinkedList的区别 Java面试题11.HashMap和HashTable的区别 Java面试题12.实现一个拷贝文件的工具类要使用字节流还是字符串 Java面试题13.线程的的实现方式?怎么启动线程?怎么区分线程? ...
import java.util.ArrayList; import java.util.List; import java.util.UUID; /** * @author: Raicho * @Description: * @program: mianshi * @create: 2020-07-17 15:32 **/ public class ...
ArrayList 和 LinkedList 的区别是什么? 并行和并发有什么区别? 说一下 runnable 和 callable 有什么区别? 线程的 run()和 start()有什么区别? 创建线程池有哪几种方式? 在 java 程序中怎么保证多线程的运行...
正确使用字符串相关类(String,StringBuffer,StringTokenizer),日期类(Date、Calendar);另外,还有ArrayList、LinkedList、HashTable、TreeSet等都涉及在内。用Java实现对数据的增、删、改、查功能。