博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【8-22】java学习笔记04
阅读量:7048 次
发布时间:2019-06-28

本文共 2936 字,大约阅读时间需要 9 分钟。


 Scanner类(java.util.scanner)


 

Scanner对象.Xxx(),hasNext()默认方法为字符串;//Returns true if this scanner has another token in its input.

(); //Finds and returns the next complete token from this scanner.
Scanner sc = new Scanner(System.in); sc.useDelimiter(正则表达式);//sc.useDelimiter("\n");以换行符区分每一个输入
while(sc.hasNext()) { System.out.println(sc.next()); }

hash值计算(Static method in class java.util. extend java.lang. )


public class haha {    public static void main(String[] args)    {        String a=new String("haha");        String b=new String("haha");        System.out.println("a的hash值:"+a.hashCode());        System.out.println("b的hash值:"+b.hashCode());        System.out.print("a的identityHashCode值:");        System.out.println(System.identityHashCode(a));        System.out.print("b的identityHashCode值:");        System.out.println(System.identityHashCode(b));    }}

runtime类(java.lang.runtime)


import java.io.IOException;public class hah {    public static void main(String[] args) throws Exception     {        Runtime rt=Runtime.getRuntime();        System.out.println(rt.availableProcessors());        System.out.println(rt.freeMemory());        System.out.println(rt.totalMemory());        System.out.println(rt.maxMemory());        rt.exec("notepad.exe");//开启新进程执行系统命令        }}

 object类


  • boolean equals(Object obj);//根据地址计算
  • int hashCode();//根据地址计算一般需重写
  • String toString();//类的tostring字符串为“类名@hashcode值”
  • protected  clone() throws
  • ......

 String类(java.lang.String java.lang.StringBuffer java.lang.StringBuilder)


  •  String对象一旦创建就成为临时变量,StringBuffer和StringBuilder类为字符串对象提供了insert append replace...等方法,可以改变字符串对象(StringBuffer为线程安全的,效果会差一点);

 Math工具类(java.lang.Math)


  •  其构造器被定义为private,因此无法创建Math对象,其多有方法都是类方法,可直接调用;
  • 提供PI和E两个类变量;

 Random工具类(java.util.Random和java.util.concurrent.ThreadLocalRandom)


  • Random类产生伪随机数,种子相同产生的随机数序列相同;
  • 使用48位的种子;
  • 使用默认种子构造Random对象时,属于同一个种子;
  • 常用时间作为种子:
    import java.util.Random;public class hah {    public static void main(String[] args) throws Exception     {            Random rand=new Random(System.currentTimeMillis());                        int i=20;            while(i>0)            {                int r=rand.nextInt();                System.out.println("r:"+r);                --i;            }    }}

 BigDecimal类(java.math.BigDecimal)


  •  使用BigDecimal(String val)构造器,保持数值准确性

    BigDecimal(String val)

    Translates the string representation of a BigDecimal into a BigDecimal.

  • 或者使用valueOf(double val)等构造

    valueOf(double val)

    Translates a double into a BigDecimal, using the double's canonical string representation provided by the Double.toString(double) method.

 时间工具类(java.util.Date和java.util.Calendar)


  •  Calendar类为抽象类,用getinstance()静态方法获取对象;
  • 可以将Date对象传个setTime()函数,设定时间;

    setTime(Date date)

    Sets this Calendar's time with the given Date.

  • 引入import static java.util.Calendar.*;包
  • set()方法有延时特性,在调用时才修改;

 时间日期类(java.time.Clock和java.time)


  •  

 正则表达式(java.util.regex.Pattern java.util.regex.Matcher)


  •  

转载于:https://www.cnblogs.com/achievec/p/java.html

你可能感兴趣的文章
C语言随笔_return答疑
查看>>
1000户网络全面加速方案
查看>>
如何为centos配置一个新的yum
查看>>
网络流入门
查看>>
mysql中按in中的数据排序
查看>>
Redis 命令参考
查看>>
DIV垂直居中
查看>>
我的友情链接
查看>>
本地通知
查看>>
Java编程经验
查看>>
CVS
查看>>
在Spring中发现java.lang.ClassCastException: $Proxy1问题解
查看>>
android教父高焕堂 成都之行
查看>>
SQL*loader实验
查看>>
awk案例更新
查看>>
可用的 kali 源(2016)
查看>>
《Tomcat日志系统详解》
查看>>
JAVA WEB基础
查看>>
采用EntityFramework.Extended 对EF进行扩展
查看>>
Mysql多源复制
查看>>