package arrayListDemo; import java.util.*; import java.util.Scanner;; public class ArrayListDemo { public static void main(String[] args) { ArrayList<String> chaoba = new ArrayList<String>();//定义动态数组,动态数组字符串 chaoba.add("超霸22"); chaoba.add("超霸333"); Arry ss=new Arry(); ss.scanfAdd(chaoba); ss.scanfRemove(chaoba); ss.scanfSet(chaoba); for(String ch:chaoba) { System.out.println(ch); } } } class Arry { Scanner sr=new Scanner(System.in); public void add(ArrayList chaoba,String s) { chaoba.add(s); Arry.print(chaoba); } public void remove(ArrayList chaoba,String s) { chaoba.remove(s); Arry.print(chaoba); } public void set(ArrayList chaoba,int x,String s) { chaoba.set(x, s); Arry.print(chaoba); } public void scanfAdd(ArrayList chaoba) { Arry ss=new Arry(); System.out.println("请输入插入内容"); String s=sr.next(); ss.add(chaoba, s); } public void scanfRemove(ArrayList chaoba) { Arry ss=new Arry(); System.out.println("请输入删除内容"); String s=sr.next(); ss.remove(chaoba, s); } public void scanfSet(ArrayList chaoba) { Arry ss=new Arry(); System.out.println("请输入修改坐标"); int x=sr.nextInt(); System.out.println("请输入被修改成的内容"); String s=sr.next(); ss.set(chaoba, x, s); } static void print(ArrayList chaoba) { System.out.println(chaoba); } }