package com.yjf.esupplier.common.test; import java.util.ArrayList; import java.util.List; /** * @author shusheng * @description * @Email shusheng@yiji.com * @date 2018/12/11 19:22 */ public class ListDemo { public static void main(String[] args) { List list = new ArrayList<>(); list.add("hello"); list.add("world"); list.add("java"); //void add(int index,Object element):在指定位置添加元素 list.add(1,"android"); System.out.println("list:"+list); //Object get(int index):获取指定位置的元素 System.out.println("get:"+list.get(2)); //Object remove(int index):根据索引删除功能,返回被删除的元素 System.out.println("remove:"+list.remove(1)); System.out.println("list:"+list); //Object set(int index, E element):根据索引修改元素,返回被修饰的元素 System.out.println("list:"+list.set(1, "javaweb")); System.out.println("list:"+list); } }
执行结果:
list:[hello, android, world, java]
get:world
remove:android
list:[hello, world, java]
list:world
list:[hello, javaweb, java]