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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。