zoukankan      html  css  js  c++  java
  • Java容器

    package notebook;
    
    import java.util.ArrayList;
    
    public class NoteBook {
     private ArrayList<String> notes =new ArrayList<String>();     //创建容器类的对象notes
    
     public void add(String s)
     {//加入笔记
      notes.add(s);
     }
    
     public void add(String s,int location)
     {//加入笔记到指定位置location
      notes.add(location, s);
     }
    
     public int getSize()
     {//返回保存笔记的条数
      return notes.size();
     }
    
     public String getNote(int index)
     {//返回某条笔记的内容
      return notes.get(index);
     }
    
     public void removeNote(int index)
     {//删除某条笔记
      notes.remove(1);
     }
    
     public String[] list()
     {//列出全部笔记内容
      String[] a = new String[notes.size()];
      notes.toArray(a);
      return a;
     }
    
     public static void main(String[] args) {
      String[] a =new String [2];
      a[0] = "first";
      a[1] = "second";
      NoteBook nb = new NoteBook();
      nb.add("first");
      nb.add("second");
      nb.add("third,1");
      System.out.println(nb.getSize());
      System.out.println(nb.getNote(0));
      System.out.println(nb.getNote(1));
      nb.removeNote(1);
      for(String s :a)
      {
       System.out.println(s);
      }
     }
    
    }
    
  • 相关阅读:
    一天进步一点点
    Flask
    Sqlalchemy 设置表编码及引擎
    threading.local
    xshell配置密码公钥登录
    linux 系统优化+定时任务
    linux命令
    xshell连接及优化
    linux前奏
    Vue Devtools--vue调式工具
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/7028649.html
Copyright © 2011-2022 走看看