正则表达式,Math,Random,system,BigInteger,BigDecimal,Data/DataFormat,Calender
来源:互联网 发布:学钢琴软件 编辑:程序博客网 时间:2024/04/29 10:31
1.正则表达式
(1)符合一定规则的字符串。
(2)正则表达式规则
A:字符
x 表示 字符x。
\\ 反斜线字符。
\n 换行符。
\r 回车符。
B:字符类
[abc] a,b,c(简单类)
[^abc] 除a,b,c的任意字符
[a-zA-Z]a-z A-Z两头的字符包括在内
[0-9] 0-9字符都包括
C:预定义字符类
. 表示任意字符。“.”字符本身用“\.”表示。
\d 代表数字:[0-9]
\w 代表单词字符:[a-zA-Z_0-9]
\W :[^w]
D:边界匹配器
^ 代表行的开头
$ 代表行的结尾
\b 代表单词边界(就是不是单词字符的地方)
E:Greedy 数量词
X? X,一次或一次也没有
X* X,零次或多次 (包括一次)
X+ X,一次或多次
X{n} X,恰好 n 次
X{n,} X,至少 n 次
X{n,m} X,至少 n 次,但是不超过 m 次
硬盘上的路径应该用\\代替\,所以在正则表达式中应该用”\\\\”。
(3)正则表达式的应用
A:判断功能
public boolean matches(String regex)
例如: String regax = "\\w+@\\w{2,6}(\\.\\w{2,3})+";
return s.matches(regax);
B:分割功能
public String[] split(String regex)
例子:String s ="91,27,46,28,50";
String[] arry = s.split(" ");
int[] arr = new int[arry.length];
//将字符数组转成int数组
for(intx=0;x<arry.length;x++)
{
arr[x] = Integer.parseInt(arry[x]);
}
C:替换功能
public String replaceAll(String regex, String replacement)
使用给定的 replacement 替换此字符串所有匹配给定的正则表达式的子字符串。
例子:String s= "qqqqqqqq22222wwwedecs34565xcdc";
String regex ="\\d+";
String ss ="";
String result = s.replaceAll(regex,ss);
System.out.println(result);
D:获取功能(Pattern和Matcher类的使用)
典型的调用顺序是
Pattern p = Pattern.compile("a*b");
(*的意思是零次或多次)
Matcher m = p.matcher("aaaaab");
boolean b = m.matches();
例子:
public static voidmain(String[] args)
{
String s ="da jia ting wo shuo bu xia wan zi xi";
//获取三个字符的字符串
String regex = "\\b\\w{3}\\b";
//把规则编译成模式对象
Pattern p = Pattern.compile(regex);
//通过模式对象得到匹配器对象
Matcher m = p.matcher(s);
//通过find方法查找,得到的是匹配的每一个子序列
//boolean b = m.find();
//System.out.println(b);
//如何的到值呢?
//group方法,
// 返回由以前匹配操作所匹配的输入子序列。 (注意,在group之前必须先调find)
while(m.find())
{
System.out.println(m.group());
}
}
2.Math类
(1)Math 类包含用于执行基本数学运算的方法,如初等指数、对数、平方根和三角函数。
(2)常见方法
A:abs 绝对值
B:ceil 向上取整
C:floor 向下取整
D:max 最大值
E:min 最小值
F:pow 一个数的多少次方
G:round 四舍五入(数字加1/2然后取整)
H:sqrt 平方根
(3)获取任意范围的随机数
(int) (Math.Random()*(end - start +1) ) + start;
3.Random
(1)用于产生随机数的类
(2)构造方法
A:Randrom() 默认种子(当前时间的毫秒值),每次产生的随机数不同
B:Random(long seed)指定种子,每次返回的随机数相同
(3)成员方法
A:int nextInt() 返回int范围内的随机数
B:int nextInt(int n)返回[0,n)以内的随机数(注意范围)
4.System
(1)系统类,提供一些有用的字段及方法。
(2)成员方法
A:运行垃圾回收器
public static voidgc()
B:退出jvm
public static voidexit(int status)
C:获取当前时间的毫秒值
public static longcurrentTimeMillis()
D:数组赋值
public static voidarraycopy(Object src,
int srcPos,
Object dest,
int destPos,
int length)
5.BigInteger
(1)针对大整数的运算
(2)构造方法
A:BigInteger(String s )
(3)成员方法
A:加 add
B:减 subtract
C:乘multiply
D:除 divide
E:商,余数
publicBigInteger[]divideAndRemainder(BigInteger val)
返回包含(this / val) 后跟(this % val) 的两个 BigInteger 的数组。
6.BigDecimal
(1)浮点数据做数据,会丢失精度,所以,针对浮点数据用该类。
(2)构造方法
A:BigDecimal(String s)
(3)成员方法
A:加
B:减
C:乘
D:除
E:自己保留小数几位
publicBigDecimal divide(BigDecimal divisor,
int scale,
RoundingMode roundingMode)
6.Data/Dataformat
(1)Data是日期类,可以精确到毫秒。
A:构造方法
Data()
Data(long time)
B:成员方法
getTime()
setTime(long time)
C:日期和毫秒值的相互转换
a.Data - 毫秒值
先创建Data对象d,然后long time= d.getTime();
b.毫秒值-Data
d.setTime(1000);
(2) DataFormat针对日期进行格式化和针对字符串进行解析的类,但是是抽象类,所以使用其子类SimpleDataFormat
A:SimpleDataFormat(String pattern)给定模式
yyyy-MM-dd HH:mm:ss
B:日期和字符串之间的转换
a.Data-String
Format()
b.String - Data
parse()
7.Calander
(1)日历类,封装了所有的日历字段值,通过统一的方法根据传入不同的日历字段可以获取值。
(2)如何得到一个日历对象?
Calendar c = Calendar.getInstance();
其本质是返回Calender的子类对象
(3)成员方法
A:得到现在的年份,月份,日
int year = c.get(Calendar.YEAR);
B:根据日历字段值和一个正负数值来确定添加还是减去日历字段值
c.add(Calendar.DATE,-1);
C:设置日历对象的年月日
c.set(2016,11,23);
例子:计算任意一年的二月有多少天
Scanner sc =newScanner(System.in);
intyear = sc.nextInt();
Calendar c = Calendar.getInstance();
c.set(year,2,1);
c.add(Calendar.DATE,-1);
System.out.println(c.get(Calendar.DATE));
注意:一般的月份是从0开始的,这里设置的时间年月日为:year-3-1
0 0
- 正则表达式,Math,Random,system,BigInteger,BigDecimal,Data/DataFormat,Calender
- day14(正则表达式,Math,Random,System,BigInteger,BigDecimal,Date等)
- 14 API-常用类(正则表达式(Pattern,Matcher),Math,Random,System,BigInteger,BigDecimal,Date/DateFormat,Calendar)
- 14. 正则表达式和常见类 (Math、Random、System、BigInteger、BigDecimal、Date_DateFormat、Calendar)
- Java中正则表达式和常用的Math、Random、System、BigInteger、BigDecimal、Date/DateFormat、Calendar类的使用
- Java基础学习笔记14——(正则表达式,Math,Random,System,BigInteger,BigDecimal,Date/DateFormat,Calendar)
- Day14 --正则表达式 Math类 Random类 System类 BigInteger类 BigDecimal类 Date类 Calendar类
- Math Random BigInteger BigDecimal
- 11.2常用类(Arrays类,Bigdecimal类,BigInteger类,System类,Calendar类,Date类,Math类,Random类,正则表达式)
- java/System/BigInteger/BigDecimal/Date/Calender
- string、math、random、bigdecimal、date、calender
- 类:BigDecimal,BigInteger,Math,System
- 简单常用类:Math 、Random、System、Integer、Character、BigInteger、BigDecimal等
- JavaSE----API之常用类(Math、Random、System、BigInteger和BigDecimal、Date和DateFormat、Calendar)
- 常见对象_Regex、Math、Random、System、BigInteger、BigDecimal、Date/DateFormat、Calendar总结
- JAVA基础复习十四-Math、Random、System、BigInteger、BigDecimal、Date、SimpleDateFormat类
- Java常用类库--Math、Random、NumberFormat、DecimalFormat、BigInteger、BigDecimal
- Java基础-14总结正则表达式,Pattern,Mactcher,Math,BigInteger,BigDeximal,System等
- 蒙特卡洛方法解非线性规划问题
- C++读写二进制文件
- 浅谈元素重叠及z-index问题
- Exception的try{}catch{}处理(return)
- 8086汇编语言 在debug中mov al,'a'或者mov ax,'ab'错误的
- 正则表达式,Math,Random,system,BigInteger,BigDecimal,Data/DataFormat,Calender
- 非CocoaPods环境 如果 使用CocoaPods环境下的项目
- HDU 1503 Advanced Fruits(还原最长公共子序列、记录路径)
- win10系统没有自带telnet服务器
- 博客园的 “随笔、文章、新闻、日记”有啥区别
- 踩过的几个坑json.dumps/含while的shell脚本/awk~
- caffe + anaconda2 重新编译后出现问题
- 64位 Ubuntu 如何安装 32位 DrCom。
- 值得学习的C/C++开源项目