Java常见的辅助函数使用
程序员文章站
2024-03-20 09:37:58
...
成员函数的使用
-
Random
产生随机数的类
构造方法:
public Random();//没有给种子,用的是默认种子,当前时间的毫秒值
public Random(long seed);//给出指定的种子
给定种子后每次得到的随机数相同
成员方法
public int nextInt();//返回的是int类型的随机数
public int nextInt(int n);返回的是[0,n)之间的随机数
demo
public class RandomDemo(){
public void main(String[] args){
Random r =new Random();
for(int x = 0; x < 10; x++){
int num = r.nextInt(10)+1;
Sysotem.out.printin(num);
}
}
}
- 正则表达式
字符x字符x。举例:’a’表示字符a
\ 反斜线字符
\n 新行
\r 回车
= **字符类**
**预定义字符**[abc] :a或者b或者c
[^abc]任何字符,除了abc
[a-zA-Z]a到z或者A到Z
[0-9]0到9的字符都包括
**边界匹配器**. 任何字符
\d数字
\w 单词字符
**数量词**^行的开头
$ 行的结尾
\b单词边界 就是不是单词字符的地方
x? x一次或者一次也没有
x* x,零次或者多次
x+ x一次或多次
x{n} 恰好 n次
x{n, } x至少n次
x{n, m}至少n次,不超多m次
- System一些方法
public static void gc();//请求运行垃圾回收器
public static void exit(int status);//终止当前运行得Java虚拟机,非0状态表示异常退出
public static long currentTimeMills();//返回以毫秒为单位的当前时间
public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) //复制数组
- Date
表示特定的瞬间,精确到毫秒
构造方法
Date():以当前时间的毫秒值创建对象
Date(long date);以给定时间的毫秒值创建对象
从Date得到/设置一个毫秒值
getTime()
setTime(long Time)
Date和String的转换
Date d = new Date()://创建对象
//给定模式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String s = sdf.format(d);
//String -- Date
String str = "2008-08-08 12:12:12";
//在把一个字符串解析为日期的时候,请注意格式必须和给定的字符串格式匹配
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dd = sdf2.parse(str);
System.out.println(dd);
- 大数运算
关于精确度
public BigDecimal(String val);构造一个大数
public BigDecimal add(BigDecimal augend)加法
public BigDecimal subtract(BigDecimal subtrahend)减法
public BigDecimal divide(BigDecimal divisor)除法
public BigDecimal multiply(BigDecimal multiplicand)乘法
关于大数
BigInteger(String val)
public BigInteger add(BigInteger val):加
public BigInteger subtract(BigInteger val):减
public BigInteger multiply(BigInteger val):乘
public BigInteger divide(BigInteger val):除
public BigInteger[] divideAndRemainder(BigInteger val):返回商和余数的数组
上一篇: hdu1754线段树
推荐阅读
-
Java常见的辅助函数使用
-
java中的Conllections辅助工具类使用
-
【JAVA】Collections辅助类的运用
-
Java并发的同步辅助类
-
Mysql中使用GROUP_CONCAT()函数会出现:BLOB问题的解决?利用cast函数
-
SQL函数 left()、charindex()的使用 博客分类: 数据库 left
-
【解决】Mysql 使用group_concat函数 出现拼接的数据缺失
-
MySQL中CONCAT()和GROUP_CONCAT()函数的使用
-
JFreeChart的使用 博客分类: java应用程序 jfreechart
-
Python 实现不使用语言自带的函数计算两个日期的差值