zoukankan      html  css  js  c++  java
  • 【Head First Java 读书笔记】(六)认识Java API

    第五章 使用Java函数库

    ArrayList

    • add(Object elem)
    • remove(int index)
    • remove(Object elem)
    • contains(Object elem)
    • isEmpty()
    • indexOf(Object elem)
    • size()
    • get(int index)

    ArrayList与一般数组的区别

    ArrayList
    ArrayList myList = new ArrayList();

    String  a  = new String("whoohoo");
    myList.add(a);
    
    String b = new String("Frog");
    myList.add(b);
    
    int theSize = myList.size();
    
    Object o = myList.get(1);
    
    myList.remove(1);
    

    一般数组

    boolean isIn = myList.contains(b);
    
    String[] myList = new String[2];
    String  a = new String("whoohoo");
    myList[0]=a;
    
    String  b = new String("Frog");
    myList[1]=b;
    
    int theSize = myList.length;
    
    String o = myList[1];
    
    myList[1]=null;
    boolean isIn = false;
    for(String item : myList){
    if(b.equals(item)){
        isIn = true;
        break;
        }
    }
    
    • 一般数组中创建时就必须确定大小,但ArrayList只需要创建处此类型的对象就行。不需要指定大小。
    • 存放对象给一般数组时必须指定位置

    Q&A

    使用import会把程序变大么,编译过程会把包或类包进去么?
    运用import只是帮你省下每个类前面的包名称而已,程序不会因为用了import而变大变慢

    为何不需要import进String类或者System类
    记得java.lang是个预先被引用的包。

  • 相关阅读:
    zz java compare 接口
    moodle 迁移
    Excel 散点图和折线图的区别
    leetcode Two Sum
    jQuery 常用方法大全<2>
    利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法
    回车验证信息
    SQL 创建密码
    高效的分页
    MVC 怎么样设置起始页
  • 原文地址:https://www.cnblogs.com/six-moon/p/4829653.html
Copyright © 2011-2022 走看看