Home  >  Article  >  Java  >  Detailed explanation and example code of java LinkedList class

Detailed explanation and example code of java LinkedList class

高洛峰
高洛峰Original
2017-02-03 17:20:451663browse

java Detailed explanation of LinkedList class

Unique functions of LinkedList

A: Add function

public void addFirst(Object e);
 
 public void addLast(Object e);

B :Special function

public Object getFirst();
public Object getLast();

C:Delete function

public Object removeFirst();
 public Object removeLast();

Example code:

import java.util.LinkedList;
  
/*
 * LinkedList的特有功能
 *
 * A:添加功能
 * public void addFirst(Object e);
 * public void addLast(Object e);
 *
 * B:特有功能
 * public Object getFirst();
 * public Object getLast();
 *
 * C:删除功能
 * public Object removeFirst();
 * public Object removeLast();
 * */
  
public class IntegerDemo {
  public static void main(String[] args) {
    // TODO Auto-generated method stub
  
    LinkedList link = new LinkedList();
  
    link.add("hello");
    link.add("world");
    link.add("java");
  
    link.addFirst("javaee");
    link.addLast("android");
  
    System.out.println("link:" + link);
  }
}

Thank you for reading, I hope it can help everyone, thank you everyone for your support of this site!

Please pay attention to the PHP Chinese website for more detailed explanations and example code related articles on the Java LinkedList class!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn