15_面向对象_02

JavaAPI

API (application  programming interface):应用程序编程接口

JavaAPI 其实就是一本程序员的字典,是JDK中提供给程序员使用的类的说明文档
这些类将底层的代码实现封装了起来,对于程序开发者来说,不需要关注底层如何实现,只需要
掌握这些类在开发中是如何使用的。所以对于开发者来说可以通过查询API的方式,
来学习Java提供的类,并得知如何使用他们。

API使用步骤:
  1.打开帮助文档
  2.点击显示,找到索引,看到输入框
  3.在输入框中输入需要查找的类,然后回车
  4.看包,Java.lang下面的类不需要导包,其他需要
  5.看类的解释说明,类的结构
  6.学习构造方法
  7.使用成员方法,ctrl + F搜索需要的成员方法。

Scanner类 扫描类 点击红线自动导包
  nextInt()
  nextDouble()
  nextLine()
  next()
Random类 随机类
随机数值
  nextInt()
  nextInt(int bound)
  nextDouble()
ArrayList类
长度可变数组 容器:插入数据,删除数据,查找数据,修改数据 crud操作
  add()
  add(int index,E element) //index索引
  remove(int index)
  remove(Object o)
  get(int index)
  ser(int index,E element)

如何使用ArrayList:

package com.zhiyou100.homework;

import java.util.ArrayList;

public class ArrayListDemo {

    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();//制定该容器中存储的数据类型为整数
        list.add(123);
        list.add(124);
        list.add(10);
        list.add(50);
        System.out.println(list.toString());
        //删除
        list.remove(0);//123删除
        list.remove(2);//直接删除10  删除第一个出现的
        System.out.println(list.toString());
        //查找查询
        Integer integer =list.get(1);//查询第二个数
        System.out.println(integer);
        //修改
        list.set(1, 100);
        System.out.println(list.toString());
        
    }

}
原文地址:https://www.cnblogs.com/rxqq/p/13892938.html