实用类(1)

JavaAPI介绍

Java应用程序接口是运行库的集合,预先定义了一些接口和类。Java语言的强大之处在于它提供了多种多样的类库,从而大大提高了程序员的编程效率和质量。
java.lang:包装类,Math类,String类。
java.util:Collection,List和Map等集合类。
java.io:包含输入输出有关的类。
java.net:包含与网络有关的类。
java.sql:包含Connection,Statement等类。

枚举

从Java SE 5.0开始,Java程序设计语言引入了一种新的类型–枚举(enum)。
枚举是指一组固定的常量组成的类型。使用关键字enum定义。

public enum Sex {,;

包装类

包装类概述

Java语言是面向对象的,但是Java中的基本数据类型却不是面向对象的,这在实际开发中存在很多不便。为了解决这个不足,设计了一个包装类。
byte:Byte
short:Short
int:Integer
long:Long
float:Float
double:Double
char:Character
boolean:Boolean

包装类和基本数据类型的转换

Integer ii=new Integer(132);
        Integer iii=new Integer("123");
        Integer a=1;//自动装箱
        int b=new Integer(2314);//自动拆箱
        int bb=new Integer("125");

valueOf方法

Integer d=Integer.valueOf(15);
        Integer dd= Integer.valueOf("55");
        int d1=d.intValue();
        int n=Integer.valueOf(str);
        Character hh='k';
        Character ch=new Character('s');
        char c=Character.valueOf('f')boolean ba=Boolean.valueOf(true);

Math类

java.lang.Math类提供了一些基本数学运算和几何运算的方法。此类中的所有方法都是静态的。
Math类方法:
ceil向上取整,floor向下取整,round四舍五入,sqrt开根号,abs取绝对值

public class TestMath {
    public static void main(String[] args) {
        System.out.println(Math.round((2.4495+1.3305)*100)/100.0);
        System.out.println(Math.PI);
        System.out.println(Math.E);
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_49143795/article/details/107697351