LinkedList 方法吐血大汇总
Posted _大木_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LinkedList 方法吐血大汇总相关的知识,希望对你有一定的参考价值。
耍起来
package com.beyond;
import java.util.*;
public class LinkedListTest
public static void main(String[] args)
List<Integer> list = new LinkedList<>();
List<Integer> list1 = new ArrayList<>();
list1.add(1);
list1.add(2);
list1.add(3);
list.add(3);
list.add(9);
System.out.println(list);
list.add(0,4);
System.out.println(list);
list.addAll(list1);
list.addAll(2,list1);
System.out.println(list);
((LinkedList<Integer>) list).addFirst(2);
System.out.println(list);
((LinkedList<Integer>) list).addLast(9);
System.out.println(list);
// list.clear();
// System.out.println(list);
System.out.println(list.get(3));
Object clone = ((LinkedList<Integer>) list).clone();
System.out.println(clone.toString());
System.out.println(list.contains(2));
//
// Iterator<Integer> iterator = ((LinkedList<Integer>) list).descendingIterator(); // 逆序遍历
// while (iterator.hasNext())
// System.out.print(iterator.next()+" ");
//
System.out.println(((LinkedList<Integer>) list).element());
System.out.println(list.indexOf(2));
System.out.println(list.lastIndexOf(2));
ListIterator<Integer> iterator = list.listIterator();
while (iterator.hasNext())
System.out.print(iterator.next()+" ");
System.out.println();
boolean offer = ((LinkedList<Integer>) list).offer(5);
System.out.println(list);
((LinkedList<Integer>) list).offerLast(0);
System.out.println(list);
System.out.println(((LinkedList<Integer>) list).peek());
System.out.println(((LinkedList<Integer>) list).peekFirst());
System.out.println(((LinkedList<Integer>) list).peekLast());
List<String> list2 = new LinkedList<>();
// System.out.println(((LinkedList<Integer>) list2).element()); // 没有则报错
// System.out.println(((LinkedList<Integer>) list2).peek());
// System.out.println(((LinkedList<Integer>) list2).peekFirst());
// System.out.println(((LinkedList<Integer>) list2).peekLast());
System.out.println(((LinkedList<Integer>) list).poll());
System.out.println(((LinkedList<Integer>) list).pollFirst());
System.out.println(((LinkedList<Integer>) list).pollLast());
System.out.println(((LinkedList<Integer>) list).pop());
System.out.println(((LinkedList<Integer>) list).pop());
((LinkedList<Integer>) list).push(1001);
System.out.println(list);
// System.out.println(((LinkedList<String>) list2).removeFirst());
list.set(0, 99);
System.out.println(list);
System.out.println(list.size());
Spliterator<Integer> spliterator = list.spliterator();
Spliterator<Integer> split = spliterator.trySplit();
int characteristics = split.characteristics();
System.out.println(characteristics);
以上是关于LinkedList 方法吐血大汇总的主要内容,如果未能解决你的问题,请参考以下文章
❤️❤️HarmonyOS(鸿蒙)全网最全资源汇总,吐血整理,赶紧收藏!❤️❤️