zoukankan      html  css  js  c++  java
  • API(Scanner、Random、ArrayList、String、Arrays、Math)

    Scanner

    import java.util.Scanner;
    /*
    public int nextInt(): to get a integer from keyboard
    public String next(): to get a string from keyboard,end with space;
    
    Scanner sc = new Scanner(System.in);
    
    */
    
    

    Random

    import java.util.Random;
    
    // 构造方法:
    // 	public Random():创建一个新的随机数生成器;
    // 成员方法:
    // 	public int nextInt(int bound):产生0~n的随机数,但是不包括n
    	
    
    

    ArrayList

    import java.util.ArrayList
    
    // 构造方法:
    // 	public ArrayList():构造一个内容为空的集合
    // 基本格式:
    // 	ArrayList<String> StringList = new ArrayList<>();
    // 	ArrayList<Integer> intList = new ArrayList<>();
    // 成员方法:
    // 	public boolean add(E e):在集合中加入元素到尾部
    // 	public E remove(int index):删除指定位置上的元素,并且返回被删除元素;
    // 	public E get(int index):获取指定位置上的元素,并且返回;
    // 	public int size():返回几个元素的个数。
    
    

    String

    import java.lang.String;
    // 位于java.lang,不用添加import语句;
    // 构造方法:
    // 	public String():构造一个空的字符串;
    // 	public String(char[] chars):以字符数组作为参数,据此构造一个字符串
    // 	public String(byte[] bytes):以字节数组作为参数,据此构造一个字符串
    // 成员方法:
    // 	1.public boolean equals(Object ojb):字符串比较
    // 	2.public boolean equalsIgoreCase(String anotherString):忽略大小写的比较
    
    // 	3.public int length():return the length of the String
    // 	4.public String concat(String str):将参数字符串连接到该字符串的末尾
    // 	5.public char charAt(int index):返回指定索引处的char值
    // 	6.public int indexOf(Strig str):返回参数字符串第一次出现在该字符串的位置,没有出现就返回-1
    // 	7.public String substring(int beginIndex):从beginIndex开始截取字符串直到结尾
    // 	8.public String substring(int beginIndex, int endIndex):从beginIndex开始截取字符串直到endIndex,不包括endIndex
    
    // 	9.public char[] toCharArray():字符串转化为字符数组
    // 	10.public byte[] getBytes():字符串转化为字节数组
    // 	11.public String replace(CharSequence target, CharSequence replacement):将字符串中的target子串全都替换为replacement
    
    // 	12.public String[] split(String regex):将字符串按照给定的规则拆分,返回一个字符串数组
    	
    

    Arrays

    提供操作数组的方法,都是静态方法

    import java.util.Arrays;
    
    1.public static String toString(int[] a):返回一直字符串
    int[] a = {1, 2, 3, 4, 5, 6};
    
    String str = Arrays.toString(a);
    System.out.println(str);// [1, 2, 3, 4, 5, 6]
    
    2.public static void sort(int[] a):排序
    
    Arrays.sort(a);
    
    
    

    Math

    import java.lang.Math

    public static double Math.abs(double a):
    
    // :返回大于等于参数的最小整数
    public static double ceil(double a)
    
    // 返回小于等于参数的最大整数
    public static double floor(double a)
    
    // 返回最接近参数的long
    public static long round(double)
    
    
  • 相关阅读:
    用 HTML 格式导出 Excel 时,如何保留显示网格线
    [转载] 让SciTE能够和IDE一样进行成员提示
    RedHat 上安装多个 mysql 实例并配置 django 连接的操作记录
    我的 SciTEGlobal.properties 配置文件
    FrameSet 不能支持透明
    RedHat 上安装 lighttpd 并配置 fastcgi + django 的记录
    系统设计与开发 辅助工具大集成终结版
    SQL Server Management Object(SMO)大大简化数据库工具的开发 几行代码开发功能强大的SQL工具
    Enterprise Solution 解决方案与源代码下载
    LLBL Gen 实体映射工具技术原理剖析
  • 原文地址:https://www.cnblogs.com/zhuobo/p/10598754.html
Copyright © 2011-2022 走看看