Arraylist查询快,增删改慢
LinkedList增删改快,查询慢
package com.controller;
import org.springframework.web.bind.annotation.*;
import java.util.LinkedList;
@RestController
@CrossOrigin
@RequestMapping("/admin")
public class AdminController{
@GetMapping("/{id}")
public LinkedList findById(@PathVariable Long id) throws InterruptedException {
LinkedList<String> list = new LinkedList<>();
list.add("dadw");
list.add("dadw1");
list.add("dadw2");
list.add("dadw3");
list.add("dadw4");
list.add("dadw5");
//头部插入
list.addFirst("dade666");
//尾部插入
list.addLast("dade88888");
//返回头部第一个元素
System.out.print(list.getFirst()+"\n");
//返回尾部第一个参数
System.out.print(list.getLast()+"\n");
//返回头部第一个参数并删除
System.out.print(list.removeFirst()+"222222\n");
//返回尾部第一个参数并删除
System.out.print(list.removeLast()+"222222\n");
return list;
}
}