package com.itheima_01; import java.util.arraylist; /* * 获取元素 * public e get(int index):返回指定索引处的元素 * 集合长度 * public int size():返回集合中的元素的个数 * 删除元素 * public boolean remove(object o):删除指定的元素,返回删除是否成功 * public e remove(int index):删除指定索引处的元素,返回被删除的元素 * 修改元素 * public e set(int index,e element):修改指定索引处的元素,返回被修改的元素 */ public class arraylistdemo2 { public static void main(string[] args) { //创建集合对象 arraylist<string> array = new arraylist<string>(); //添加元素 array.add("hello"); array.add("world"); array.add("java"); //public e get(int index):返回指定索引处的元素 //system.out.println("get:"+array.get(0)); //system.out.println("get:"+array.get(1)); //system.out.println("get:"+array.get(2)); //public int size():返回集合中的元素的个数 //system.out.println("size:"+array.size()); //public boolean remove(object o):删除指定的元素,返回删除是否成功 //system.out.println("remove:"+array.remove("world"));//true //system.out.println("remove:"+array.remove("world"));//false //public e remove(int index):删除指定索引处的元素,返回被删除的元素 //system.out.println("remove:"+array.remove(0)); //public e set(int index,e element):修改指定索引处的元素,返回被修改的元素 system.out.println("set:"+array.set(1, "android")); //输出 system.out.println("array:"+array); } }
集合的遍历是通过size()方法和get()方法结合使用。2018-10-19 00:13:35
如对本文有疑问, 点击进行留言回复!!
详解SpringBoot修改启动端口server.port的四种方式
网友评论