Principles and examples of Java LinkedList

This article mainly introduces the principle and example explanation of Java LinkedList. The example code is introduced in great detail, which has a certain reference value for everyone's study or work. Friends in need can refer to it

Definition: LinkedList is a linked list structure. It is convenient to add and delete elements, but it is inconvenient to query. It is suitable for closing operations.

With a specific object, use the object to call a specific method

add

 // 添加元素 //在中间添加元素
 arr.add("H");

Addfirst: adds an element to the front of the collection

 // 在链表头部添加元素
 arr.addFirst("F");

Addlast: adds an element at the end of the collection

 //在链表尾部添加元素
 arr.addLast("L");

Removefirst removelast: deletes the first element and the last element

 //删除元素
     arr.removeFirst();

Getfirst getlast: get the first element and get the last element

//获取元素
    String s1=arr.getLast();

Isempty: used to judge whether there are elements in the collection. If there are elements, false is returned

Pop: pop the elements in the collection from front to back from the stack

//当arr中有元素时,返回False,使用!取反
    while(!arr.isEmpty()){
      //将数组中的数据弹出
      Sy@R_419_2354@.out.println("这是pop方法"+arr.pop());
    }

Push: adds an element to the collection

   //为数组添加新的数据
     arr.push("xin");

The above is the whole content of this article. I hope it will help you in your study, and I hope you will support us a lot.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>