Collection下的List接口
来源:互联网 发布:杭州恩牛网络借壳上市 编辑:程序博客网 时间:2024/06/05 19:14
1.List接口是一个有序接口,可以根据0,1,2,3这样的顺序进行索引
其中List中有如下方法
1.add(index,element);//将指定元素加入到指定位置
2.addAll(index,c);将c集合加入到index后
3.get(index)指定其index,返回其对象
4.indexof(object o)返回对象在list中的位置
5.lastindexof(object o)返回对象o在list中的最后元素的位置
6.remove(index)返回并返回被删除的元素
7.set(index,element)设置指定位置的元素被改变,并且返回新元素
8.sublist(index1,index2)返回从index1处元素到index2的元素
具体代码如下:
import java.awt.List;import java.util.ArrayList;import java.util.Collection;import java.util.HashSet;public class List1 {public static void main(String []args){ArrayList lsList = new ArrayList();lsList.add("1");lsList.add("2");lsList.add("3");System.out.println(lsList);lsList.add(3, "4");System.out.println(lsList);Collection collection = new HashSet();collection.add("5");collection.add("6");lsList.addAll(4, collection);System.out.println(lsList);System.out.println(lsList.get(3));System.out.println(lsList.indexOf("5"));System.out.println(lsList.remove(5));System.out.println(lsList.set(4, "1"));System.out.println(lsList);System.out.println(lsList.subList(0, 5));for(int i = 0;i<lsList.size();i++){System.out.println(lsList.get(i));}}}
返回值:
0 0
- Collection下的List接口
- java中collection接口下list arraylist vector以及 map接口下的hashmap hashtable详解
- Collection 接口 & List 接口
- 集合Collection接口下Set接口List接口
- Collection接口下的集合
- 集合collection 下List接口和Set接口
- Map、Collection、List接口的总结
- Collection和List接口的remove方法
- 深入Collection集合的子接口List
- 接口Collection和List
- java集合(Collection接口下的 List、Set 深入理解)
- Collection接口和List接口中常用的方法
- Java:Collection.List接口实现
- Collection接口、List接口及迭代器
- Collection接口之List子接口详解
- java中Collection接口&List接口
- List接口下的集合
- List,Set,Map是否继承自Collection接口? 答:List,Set是,Map不是。 Collection是最基本的集合接口,一个Collection代表一组Object,即Colle
- [Servlet]什么是Servlet
- Hadoop之——分布式集群安装过程简化版
- Matlab之统计函数
- jsp ,servlet中路径
- 简单利用CodeDom动态编译的例子
- Collection下的List接口
- the solution of CountNonDivisible by Codility
- 线程的两种创建方式:Thread类和Runnable接口,它们都要复写run方法
- android intent打开各种文件的方法
- SQL中INNER JOIN、LEFT JOIN、RIGHT JOIN、FULL JOIN区别
- 欢迎使用CSDN-markdown编辑器
- NSString笔记与OC"命名空间"
- 5.2-4
- 15HD_OJ——超级楼梯(斐波那契数列)