实体类

1.枚举
(1)由一组固定的常量组成
(2)枚举可以使用是常量,switch
(3)语法:
①有属性,有方法
public enum 枚举名{
类型1(属性),类型2(属性),。。。,类型n(属性);
属性1;
属性2;。。。。
//私有的构造方法
private 枚举名(属性1,属性2.。。。){
This.属性1=属性1;
This.属性2=属性2;。。。。。
}
//自定义其他方法
//get set 方法

}
②没有属性
public enum 枚举名{
类型1,类型2,。。。,类型n;
}
2.基本数据类型对应的包装类 — 包装类都在java.lang.*;
(1)byte - Byte
(2)int - Integer
(3)short - Short
(4)long - Long
(5)float - Float
(6)double - Double
(7)char - Character
(8)boolean - Boolean
3.基本数据类型转换为包装类 ,装箱的方法
(1)构造方法 Integer num = new Integer(1);
(2)静态方法 Integer num = Integer .valueOf(2);
4.包装类转换为基本数据类型.拆箱的方法
(1)XXXValue()
Integer num = new Integer(1);
Int num1 = num .intValue();
5.基本数据类型转换为字符串
(1)String num1 = 1+””;
(2)String num2 = Integer.toString(2);
(3)Integer num = new Integer(1); num .toString()

6.包装类转换为字符串
(1)Integer num = new Integer(1);
num.toString();

7.包装类构造方法
(1)包装类 对象名 = new 包装类(基本数据类型值);
(2)包装类 对象名 = new 包装类(“基本数据类型值”);
①Character 除外 ‘’
②数值型包装类,字符串必须是可以转换为数值型 ,否则会出现NumberFormatException
③Boolean 不区分true /false 大小
8.装箱和拆箱
(1)装箱:— 基本数据类型转换为包装类
(2)拆箱:— 包装类转换为基本数据类型
(3)基本数据类型可以自动转换为包装类
(4)结合向上转型向下转型记忆
9.Math 常用方法
System.out.println(Math.E);//自然底数
System.out.println(Math.PI);//圆周率
//四舍五入
System.out.println(Math.round(3.4));//3
System.out.println(Math.round(3.6));//4
//向上取整
System.out.println(Math.ceil(3.4));//4
System.out.println(Math.ceil(3.6));//4
//向下取整
System.out.println(Math.floor(3.4));//3
System.out.println(Math.floor(3.6));//3

	//最大值
	System.out.println(Math.max(4, 8));//8
	//最小值
	System.out.println(Math.min(4, 8));//4
	
	//绝对值
	System.out.println(Math.abs(3.4));//3.4
	System.out.println(Math.abs(-3.4));//3.4
	
	//随机数   0-1(不包含1)
	System.out.println(Math.random());
	//0-100 随机数
	System.out.println(Math.floor(Math.random()*100));

10.包装类的常用方法
/**
* 基本数据类型转换为包装类
* 1.public static Type valueOf(type value)
* 2.public static Type valueOf(String value) Character 不可以
/
private static void test5() {
//1
Integer num = Integer.valueOf(2);
Character c = Character.valueOf(‘3’);
//2
Integer num1 = Integer.valueOf(“2”);
//Character c1 = Character.valueOf(“3”);
}
/
*
* 将字符串形式基本数据类型数据转换为对应的基本数据类型
* Character除外
* public static type parseType(String type)
*/
private static void test4() {
int num = Integer.parseInt(“22”);

}
/**
 * 将数据类型(基本数据类型)转换为字符串
 * 	1.静态方法 : 包装类.toString(参数)
 *  2.连接“”   :  +""
 * 
 */
private static void test3() {
	//方法1
	String num1 = Integer.toString(2);
	//方法2
	String num2 =2+"";
	
}

/**
 * 将包装类转换为基本数据类型 普通方法XXXValue()
 */
private static void test2() {
	Integer num = new Integer(8);
	int num1 = num.intValue();
	
}

/**
 * 演示包装类的构造方法
 */
private static void test1() {
	// 包装类构造方法
	Integer num1 = new Integer(1);
	Integer num2 = new Integer("2");
	// Character
	Character chara = new Character('a');
	// Boolean
	Boolean bo = new Boolean("tRuE");
	System.out.println(num1);
	System.out.println(num2);
	System.out.println(chara);
	System.out.println(bo);

	Double double1 = new Double("AAA");

}

11.随机数Random
(1)使用Math 获取随机数
//随机数 0-1(不包含1)
System.out.println(Math.random());
//0-100 随机数
System.out.println(Math.floor(Math.random()*100));
(2)使用Random 获取随机数
Random random = new Random();
//0-10(不包含10)
int num = random.nextInt(10);
(3)生成两个相同随机数
1)使用同一个种子生成两个随机数生成器(随机数对象)
2)两个生成器要调用同一个方法
3)调用的同一个方法次数一定要相同 num1_1==num2

Random random1 = new Random(10);
Random random2 = new Random(10);
int num1_1 = random1.nextInt(10);
int num1_2 = random1.nextInt(10);
int num2 = random2.nextInt(10);

12.String
(1)== & equals
①如果是String 类型(重写equals) equals 比较的是值
②如果不重写equals方法,== equals 是一样的
③如果重写equals方法,要看具体的重写规则

(2)常用方法
①equalsIgnoreCase()方法 忽略大小写比较
②toLowerCase()方法 转换为小写
③toUpperCase()方法 转换为大写

(3)获取长度 :字符串.length() (方法)
数据获取长度: 数组名.length (属性)
集合的长度: 集合名.size() (方法)
(4)替换字符串
1.原来字符串不会被改变
2.替换之后是一个新的字符串
3.String 是 final 类型的

(5)常用方法

(6)连接字符串的两种方法
①“+”
②concat(“”)
System.out.println(“王昊天”+“和张昆是好朋友”);
System.out.println(“王昊天”.concat(“和张昆是好朋友”));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值