企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# Java - 从`LinkedList`的特定索引获取元素 > 原文: [https://beginnersbook.com/2014/07/java-get-element-from-specific-index-of-linkedlist-example/](https://beginnersbook.com/2014/07/java-get-element-from-specific-index-of-linkedlist-example/) 在这个例子中,我们将看到如何使用[`get(int index)`](https://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html#get(int))方法从`LinkedList`的特定索引中获取元素: `public E get(int index)`:返回此列表中指定位置的元素。 ```java import java.util.LinkedList; public class GetElementExample { public static void main(String[] args) { // Creating LinkedList of String Elements LinkedList<String> linkedlist = new LinkedList<String>(); // Populating it with String values linkedlist.add("AA"); linkedlist.add("BB"); linkedlist.add("CC"); linkedlist.add("DD"); linkedlist.add("EE"); System.out.println("LinkedList Elements : "); //get(i) returns element present at index i for(int i=0; i < linkedlist.size(); i++){ System.out.println("Element at index "+i+" is: "+linkedlist.get(i)); } } } ``` **输出:** ```java LinkedList Elements : Element at index 0 is: AA Element at index 1 is: BB Element at index 2 is: CC Element at index 3 is: DD Element at index 4 is: EE ```