package tian;

import java.util.ArrayList;
import java.util.List;
/**
 * @description List 的部分方法
 * @author 
 *
 */
public class MyList_1 {
 public static void main(String[] args) {
  String a = "A", b = "B", c = "C", d = "D", repeat = "Repeat";
  
        //indexOf(Object obj)方法和lastIndexOf(Object obj)方法
  
  List<String> list = new ArrayList<String>();
  list.add(a);          // 索引位置为 0
  list.add(repeat);      // 索引位置为 1
  list.add(b);          // 索引位置为 2
  list.add(repeat);      // 索引位置为 3

  list.add(c);          // 索引位置为 4
  list.add(repeat);      // 索引位置为 5
  list.add(d);          // 索引位置为 6
//  System.out.println(list.indexOf(repeat));
//  System.out.println(list.lastIndexOf(repeat));
//  System.out.println(list.indexOf(b));
//  System.out.println(list.lastIndexOf(b));
   // 1 5 2 2
  //subList(int fromIndex, int toIndex)方法截取现有List集合中的部分对象生成新的List集合时
  list = list.subList(0, 3);// 利用从索引位置 1 到 3 的对象重新生成一个List集合
    for (int i = 0; i < list.size(); i++) {
     System.out.println(list.get(i));
     }
  }

 }