当前位置 : 主页 > 编程语言 > c++ >

7-5 jmu-Java-02基本语法-08-ArrayList入门

来源:互联网 收集:自由互联 发布时间:2021-06-30
gistfile1.txt import java.util.ArrayList;import java.util.Scanner;public class Main { private static Scanner in; public static void main(String[] args) { in=new Scanner(System.in); ArrayList strList=new ArrayList(); while (true) { String s=
gistfile1.txt
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
    private static Scanner in;
    public static void main(String[] args)
    {
        in=new Scanner(System.in);
        ArrayList
 
   strList=new ArrayList<>();
        while (true)
        {
            String s=in.next();
            while(!s.equals("!!end!!"))
            {
                strList.add(s);
                s=in.next();
            }
            if(strList.size()>0)
            {
                strList.add(0,"begin");
                strList.add(strList.size(),"end");
            }
            System.out.println(strList);
            String str=in.next();
            int a;
            a=strList.indexOf(str);
            if(a>=0)
            {
                System.out.println("true");
                System.out.println(a);
                System.out.println(strList.lastIndexOf(str));
            }
            else {
                System.out.println("false");
                System.out.println(a);
            }
            System.out.println(strList.get(0));
            strList.remove(0);
            System.out.println(strList);
            str=in.next();
            strList.set(1,str);
            System.out.println(strList);
            str=in.next();
            ArrayList
  
    strList1=new ArrayList<>(); for (String e:strList) { if(e.indexOf(str)>=0) strList1.add(e); } System.out.println(strList1); a=strList.indexOf(str); if(a>=0) strList.remove(a); System.out.println(strList); strList.clear(); System.out.println(strList+" "+strList.size()+","+strList.isEmpty()); } } }
  
 
网友评论