实例 Java getFirst() 方法实例

x
 
import java.util.LinkedList;
public class Main {
  public static void main(String[] args) {
    LinkedList<String> cars = new LinkedList<String>();
    cars.add("Volvo");
    cars.add("BMW");
    cars.add("Ford");
    cars.add("Mazda");
    
    // Use getFirst() to display the first item in the list
    System.out.println(cars.getFirst());
  }
}
                    

输出结果

Volvo