进阶day02-List接口的特点
This commit is contained in:
42
javaSE-day03/src/com/inmind/list01/ListDemo01.java
Normal file
42
javaSE-day03/src/com/inmind/list01/ListDemo01.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.inmind.list01;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
List接口是单列集合Collection接口的子接口
|
||||
1.List接口的特点
|
||||
a.存取有序
|
||||
b.有索引
|
||||
c.可以重复
|
||||
|
||||
2.List接口的常用的实现类
|
||||
ArrayList Linkedlist
|
||||
|
||||
3.List接口是Collection接口的子接口,所以昨天学习的所有的Collection的常用方法,它都能用
|
||||
*/
|
||||
public class ListDemo01 {
|
||||
public static void main(String[] args) {
|
||||
//创建List集合
|
||||
List<String> lists = new ArrayList<>();
|
||||
lists.add("刘备");
|
||||
lists.add("关羽");
|
||||
lists.add("张飞");
|
||||
System.out.println(lists);//重写了toString
|
||||
|
||||
lists.remove("张飞");
|
||||
System.out.println(lists);
|
||||
|
||||
System.out.println(lists.contains("张飞"));//false
|
||||
|
||||
System.out.println(lists.isEmpty());//false
|
||||
|
||||
System.out.println(lists.size());//2
|
||||
|
||||
lists.clear();
|
||||
System.out.println(lists.size());//0
|
||||
|
||||
Object[] array = lists.toArray();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user