AbstractSequentialList的get()方法用於從AbstractSequentialList獲取或檢索特定索引處的元素。
用法:
AbstractSequentialList.get(int index)
參數:參數index是整數數據類型,用於指定要從AbstractSequentialList中提取的元素的位置或索引。
返回值:該方法返回存在於參數索引指定位置的元素。
以下示例程序旨在說明Java.util.AbstractSequentialList.get()方法:
範例1:
// Java code to illustrate get() method
import java.util.*;
import java.util.AbstractSequentialList;
public class AbstractSequentialListDemo {
public static void main(String args[])
{
// Creating an empty AbstractSequentialList
AbstractSequentialList<String>
absqlist = new LinkedList<String>();
// Use add() method to add elements
absqlist.add("Geeks");
absqlist.add("for");
absqlist.add("Geeks");
absqlist.add("10");
absqlist.add("20");
// Displaying the list
System.out.println("AbstractSequentialList:"
+ absqlist);
// Fetching the specific element from the list
System.out.println("The element is:"
+ absqlist.get(2));
}
}
輸出:
AbstractSequentialList:[Geeks, for, Geeks, 10, 20] The element is:Geeks
範例2:
// Java code to illustrate get() method
import java.util.*;
import java.util.AbstractSequentialList;
public class AbstractSequentialListDemo {
public static void main(String args[])
{
// Creating an empty AbstractSequentialList
AbstractSequentialList<Integer>
absqlist = new LinkedList<Integer>();
// Use add() method to add elements
absqlist.add(1);
absqlist.add(2);
absqlist.add(3);
absqlist.add(4);
absqlist.add(5);
// Displaying the list
System.out.println("AbstractSequentialList:"
+ absqlist);
// Fetching the specific element from the list
System.out.println("The element is:"
+ absqlist.get(4));
}
}
輸出:
AbstractSequentialList:[1, 2, 3, 4, 5] The element is:5
相關用法
- Java AbstractSequentialList set()用法及代碼示例
- Java AbstractSequentialList addAll()用法及代碼示例
- Java AbstractSequentialList remove()用法及代碼示例
- Java AbstractSequentialList用法及代碼示例
- Java AbstractSequentialList contains()用法及代碼示例
- Java AbstractSequentialList hashCode()用法及代碼示例
- Java AbstractSequentialList indexOf()用法及代碼示例
- Java AbstractSequentialList equals()用法及代碼示例
- Java AbstractSequentialList clear()用法及代碼示例
- Java AbstractSequentialList lastIndexOf()用法及代碼示例
- Java AbstractSequentialList conatinsAll()用法及代碼示例
- Java AbstractSequentialList set(int, Object)用法及代碼示例
- Java AbstractSequentialList toArray(T[])用法及代碼示例
- Java AbstractSequentialList retainAll()用法及代碼示例
- Java AbstractSequentialList toArray()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 AbstractSequentialList get() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。