NumberUtils、ArrayUtils和RandomUtils工具类用法
一、NumberUtils工具类
/*1.NumberUtils.isNumber():判断字符串是否是数字*/
NumberUtils.isNumber("5.96");//结果是true
NumberUtils.isNumber("s5");//结果是false
NumberUtils.isNumber("0000000000596");//结果是true /*2.NumberUtils.isDigits():判断字符串中是否全为数字*/
NumberUtils.isDigits("0000000000.596");//false
NumberUtils.isDigits("0000000000596");//true /*3.NumberUtils.toInt():字符串转换为整数*/
NumberUtils.toInt("5");
NumberUtils.toLong("5");
NumberUtils.toByte("3");
NumberUtils.toFloat("3.2");
NumberUtils.toDouble("4");
NumberUtils.toShort("3"); /*4.NumberUtils.max():找出最大的一个*/
NumberUtils.max(newint[]{3,5,6});//结果是6
NumberUtils.max(3,1,7);//结果是7 /*5.NumberUtils.min():找出最小的一个*/
NumberUtils.min(newint[]{3,5,6});//结果是6
NumberUtils.min(3,1,7);//结果是7 /*6.NumberUtils.createBigDecimal()通过字符串创建BigDecimal类型,支持long、int、float、double、number等数值*/
NumberUtils.createBigDecimal("1");
NumberUtils.createLong("1");
NumberUtils.createInteger("1"); 二、ArrayUtils工具类
/*1.ArrayUtils.isEmpty(strs):判断数组是否为空, 不为空返回false, 为空true*/
ArrayUtils.isEmpty(new String[]{"21","是"});//结果是false
ArrayUtils.isEmpty(new String[]{""});//结果是false
ArrayUtils.isEmpty(new String[]{null});//结果是false
ArrayUtils.isEmpty(new String[]{});//结果是true /*2.ArrayUtils.isNotEmpty(strs):判断数组是否不为空,不为空返回true,为空false*/
ArrayUtils.isNotEmpty(new String[]{"21","是"});//结果是true
ArrayUtils.isNotEmpty(new String[]{""});//结果是true
ArrayUtils.isNotEmpty(new String[]{});//结果是false /*3.ArrayUtils.isSameLength(strs,strs2):判断两个数组长度是否相等,长度相等返回true,否则返回false。相比较的两个数组类型必须相同*/
ArrayUtils.isSameLength(new String[]{"21","是"},new String[]{"21","是"});//返回false /*4.ArrayUtils.isSameType(strs,strs2):判断两个数组的类型是否相同,相同返回true,否则返回false*/
ArrayUtils.isSameType(new String[]{"21","是"},newInteger[]{3}); /*5.ArrayUtils.isEquals(strs,strs2)判断两个数组是否相等*/
ArrayUtils.isEquals(strs,strs);//结果是true /*6.ArrayUtils.toString()将一个数组转换成String,用于打印*/
ArrayUtils.toString(new String[]{"21","是"});//结果是:{21,是} /*7.ArrayUtils.clone赋值(克隆)数组*/
Object[]s=ArrayUtils.clone(newObject[]{"33","yy"}); /*8.ArrayUtils.subarray截取子数组:根据起始索引startIndexInclusive到结束索引startIndexInclusive*/
Object[]s1=ArrayUtils.subarray(newObject[]{"33","yy","uu"},0,1);//结果是返回数组:[33]
Object[]s2=ArrayUtils.subarray(newObject[]{"33","yy","uu"},0,2);//结果是返回数组:[33,yy] /*9.ArrayUtils.indexOf查询某个object在数组中的位置,可是指定起始搜索位置*/
intindex=ArrayUtils.indexOf(newObject[]{"33","yy","uu"},"uu");//结果是2
intindex1=ArrayUtils.indexOf(newObject[]{"33","yy","uu"},"uu",2);//结果是2
intindex3=ArrayUtils.indexOf(newObject[]{"33","yy","uu"},"uu",3);//结果是-1 /*10.ArrayUtils.lastIndexOf反向查询某个object在数组中的位置,可以指定起始搜索位置*/
intindex11=ArrayUtils.lastIndexOf(newObject[]{"33","yy","uu"},"33");//结果是0
intindex22=ArrayUtils.lastIndexOf(newObject[]{"33","yy","uu"},"33",2); /*11.ArrayUtils.contains查询某个object是否在数组中*/
ArrayUtils.contains(new String[]{"1", "2", "3"}, "11"); /*12.ArrayUtils.reverse反转数组*/
ArrayUtils.reverse(new String[]{"22","yy"});//结果是:{"yy","22"} /*13.ArrayUtils.add添加一object到数组*/
String[] t={"22","yy"};
String[] gg=(String[])ArrayUtils.add(t,"jj");//{"22","yy","jj"} /*14.ArrayUtils.addAll合并两个数组*/
String[]ggo=(String[])ArrayUtils.addAll(new String[]{"22","yy"},new String[]{"jj"});//结果是:[22,yy,jj]
ArrayUtils.addAll(new String[]{"22","yy"},new String[]{"jj", "jj"}); //结果是:[22,yy,jj,jj] /*15.ArrayUtils.remove删除数组某个位置的元素*/
String[]gg4=(String[])ArrayUtils.remove(new String[]{"22","yy"},1); /*16.ArrayUtils.removeElement删除数组中某个对象*/
String[]ggpp=(String[])ArrayUtils.removeElement(new String[]{"22","yy"},"yy"); 三、RandomUtils工具类
RandomUtils帮助我们产生随机数,不止是数字类型,连boolean类型都可以通过RandomUtils产生,RandomStringUtils生成字符随机数。
RandomUtils.nextBoolean();
RandomUtils.nextDouble();
RandomUtils.nextLong();
// 注意这里传入的参数不是随机种子,而是在0~1000之间产生一位随机数
RandomUtils.nextInt(1000);
---------------------------------------------------------------------------------
Blog:http://www.cnblogs.com/linjiqin/
Hadoop交流群(250363249)、Java+Oracle交流群(158560018)
题外话:
本人来自铁观音的发源地——泉州安溪,有需要正宗安溪铁观音的友友欢迎Q我:416501600。
NumberUtils、ArrayUtils和RandomUtils工具类用法的更多相关文章
- Java:集合,Arrays工具类用法
1. 描述 Arrays工具类提供了针对数组(Array)的一些操作,比如排序.搜索.将数组(Array)转换列表(List)等等,都为静态(static)方法: binarySearch - 使用二 ...
- Java:集合,Collections工具类用法
Collections工具类提供了大量针对Collection/Map的操作,总体可分为四类,都为静态(static)方法: 1. 排序操作(主要针对List接口相关) reverse(List li ...
- hibernate criteria Restrictions工具类用法
CriteriaQuery cq = new CriteriaQuery(TSUser.class, dataGrid); // 查询条件组装器 org.jeecgframework.core.ext ...
- StringUtils工具类用法
/*1.字符串以prefix开始*/ StringUtils.startsWith("sssdf","");//结果是:true StringUtils.sta ...
- JAVA时间工具类用法
1.获得N天前的TIMESTAMP Calendar cl = Calendar.getInstance(); cl.add(Calendar.DAY_OF_YEAR, -7); Date date ...
- Java 数字数组随机数工具类 NumberUtils、ArrayUtils、RandomUtils用法
commons-lang3-3-3.8.1 //----------------------------------------------------------------------- /** ...
- JS 工具类
之前工作用的JavaScript比较多,总结了一下工具类,和大家分享一下,有不足之处还请多多见谅!! 1. 数组工具类(arrayUtils) var arrayUtils = {}; (functi ...
- 2015第30周三Spring常用工具类
文件资源操作 文件资源的操作是应用程序中常见的功能,如当上传一个文件后将其保存在特定目录下,从指定地址加载一个配置文件等等.我们一般使用 JDK 的 I/O 处理类完成这些操作,但对于一般的应用程序来 ...
- Spring 常用的一些工具类
学习Java的人,或者开发很多项目,都需要使用到Spring 这个框架,这个框架对于java程序员来说.学好spring 就不怕找不到工作.我们时常会写一些工具类,但是有些时候 我们不清楚,我们些的工 ...
随机推荐
- Python中字符串、列表、元组、集合、字典中的一些知识,有些不太常见
————————笔记——————————# 字符串1. 字符串是不可变的.2. 字符串切片输出:`[start:end:step]`.使用`a[::-1]`倒序输出字符串.3. `str.split( ...
- C++高级编程2. 静态动态链接库
C++高级编程2. 静态动态链接库20131018 1.动态链接库和静态链接库的区别: 静态链接库就是把lib文件中用到的函数代码直接连接进目标程序,程序运行的时候不在需要其他的库文件:动态链接库是把 ...
- bzoj3402
题解: spfa最短路 然后枚举判断奇数 代码: #include<bits/stdc++.h> using namespace std; ; ]; void jb(int x,int y ...
- zoj 2976 Light Bulbs(暴力枚举)
Light Bulbs Time Limit: 2 Seconds Memory Limit: 65536 KB Wildleopard had fallen in love with hi ...
- 【javascript基础】函数前面的一元操作符
在函数前面加:+ ; ~ ! - 等等一元操作符,javascript 引擎都会将后面的statement转换成表达式(expression),这样就可以调用了.
- 【linux】VirtualBox-“please use a kernel appropriate for your cpu”
This kernel requires the following features not present on the CPU:paeUnable to boot – please use a ...
- L162
More than 250 corporate signatories joined together to try and deal with plastic pollution in an ann ...
- L146 Space Station Hole Cause Will Be Determined
The head of the U.S. space agency said Tuesday he's sure that investigators will determine the cause ...
- vue.js 源代码学习笔记 ----- core lifecycle
/* @flow */ import config from '../config' import Watcher from '../observer/watcher' import { mark, ...
- Linux:数据流重定向
1)垃圾桶黑洞 /dev/null command > /dev/null 2)stdout与stderr写入同一个文件 command > filename >& comm ...