API - 03

 
 
 
API(Application Programming Interface),应用程序编程接口。 

Scanner

一个可以解析基本类型和字符串的简单文本扫描器。 例如,以下代码使用户能够从 System.in 中读取一个数:
sc.nextInt();
sc.next();
 

Random

此类的实例用于生成伪随机数。
 

ArrayList

是大小可变的数组的实现,存储在内的数据称为元素。ArrayList 中可不断添加元素,其大小也自动增长。
java.util.ArrayList <E> :<E> ,表示一种指定的数据类型,叫做泛型。 E ,取自Element(元素)的首字母。在出现 E 的地方,我们使用一种引用数据类型将其替换即可.

成员方法:

public boolean add(E e);
public E remove(int index);
public E get(int index);
public int size();
 
ArrayList对象不能存储基本类型,只能存储引用类型的数据。
 

String

特点:
1. 字符串不变:字符串的值在创建后不能被更改。
2. 因为String对象是不可变的,所以它们可以被共享。
3. "abc" 等效于 char[] data={ 'a' , 'b' , 'c' } 。
 

构造方法:

public String()
public String(char[] value)
public String(byte[] bytes)

常用方法:

public boolean equals (Object anObject)
public boolean equalsIgnoreCase (String anotherString)
public int length ()
public String concat (String str)
public char charAt (int index)
public int indexOf (String str)
public String substring (int beginIndex)
public String substring (int beginIndex, int endIndex)
public char[] toCharArray ()
public byte[] getBytes ()
public String replace (CharSequence target, CharSequence replacement)
public String[] split(String regex)
 

static

它可以用来修饰, 成员变量和成员方法,被修饰的成员是属于类的,而不是单单是属于某个对象的。
 
static 数据类型 变量名;
static int numberID;
 
修饰符 static 返回值类型 方法名 (参数列表){
// 执行语句
}
public static void showNum() {
System.out.println("num:" + numberOfStudent);
}
 

静态方法调用的注意事项:

静态方法可以直接访问类变量和静态方法。
静态方法不能直接访问普通成员变量或成员方法。反之,成员方法可以直接访问类变量或静态方法。
静态方法中,不能使用this关键字。

静态代码块:

作用:给类变量进行初始化赋值。
小贴士:
static 关键字,可以修饰变量、方法和代码块。在使用的过程中,其主要目的还是想在不创建对象的情况下,去调用方法。
 

Arrays

操作数组的各种方法

常用方法:

public static String toString(int[] a)
public static void sort(int[] a)
 

Math

执行基本数学运算的方法,如初等指数、对数、平方根和三角函数。
public static double abs(double a)
public static double ceil(double a)
public static double floor(double a)
public static long round(double a)
 
 
 
 

猜你喜欢

转载自www.cnblogs.com/alice-bj/p/12227273.html