您的位置:首页 > 其它

Set,Map,包装类工具类

2016-03-11 20:54 225 查看
package Leidejihe;

import java.util.Random;

public class Baozhuanglei {

public static void main(String[] args) {

//包装类Long型
Long l=new Long(100);

//用包装类把字符串转成数值

Long l1=new Long("1000");
//
//        String str=1000+"";//把1000转成字符串的
//        System.out.println(str);
System.out.println(l1);
//从包装类转成基本数据类型
Long l2=l1.longValue();
System.out.println("l2="+l2);

Long l3=Long.parseLong("12999");

System.out.println("直接转:Long.parseLong()"+l3);

//int型
Integer i=new Integer("1000");

Integer.parseInt("100");

//float

Float f=new Float("123.45");
Float.parseFloat("123.456");

//Double
Double d=new Double("1234.567");
Double.parseDouble("123456.78");

//boolean型
Boolean b=new Boolean("aaaaa");
System.out.println(b.booleanValue());

Boolean b1=new Boolean("true");
System.out.println(b1);

//数学工具类。Math不能实例化,全是静态的方法
System.out.println(Math.PI);

//四舍五入
Math.round(1234.56);
System.out.println(Math.round(1234.56));
double d1=12.345678;
System.out.println("d1="+d1);
System.out.println("d1四舍五入:"+Math.round(d1));
System.out.println("d1保留两位小数:"+Math.round(d1*100)/100.0);//转成double型

//去小数点取整:下限值,上限值。返回double型
System.out.println("舍去小数点,下限值:"+Math.floor(d1));
System.out.println("舍去小数点,上限值:"+Math.ceil(d1));

//随机数Random。
//random只产生0-1之间的数,要取0-100的数,先乘以100
System.out.println("第一次随机:"+Math.random());
System.out.println("第二次随机:"+Math.random());

Random r=new Random();

//随机数种子
//伪随机数
//根据种子计算出来的
//由种子决定随机数的产生序列
//默认时间做种子,没刷新一次,随机数更新一次
//r=new Random(10);//每次产生的随机数一样
System.out.println("范围内的随机数:");
for(int j=0;j<1;j++)
{
System.out.println(r.nextInt(10));
}


View Code

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: