commons-lang3-3-3.8.1

   //-----------------------------------------------------------------------
/**
* <p>Checks whether the <code>String</code> contains only
* digit characters.</p>
*
* <p><code>Null</code> and empty String will return
* <code>false</code>.</p>
*
* @param str the <code>String</code> to check
* @return <code>true</code> if str contains only Unicode numeric
*/
public static boolean isDigits(final String str) {
return StringUtils.isNumeric(str);
}
    /**
* <p>Checks if the CharSequence contains only Unicode digits.
* A decimal point is not a Unicode digit and returns false.</p>
*
* <p>{@code null} will return {@code false}.
* An empty CharSequence (length()=0) will return {@code false}.</p>
*
* <p>Note that the method does not allow for a leading sign, either positive or negative.
* Also, if a String passes the numeric test, it may still generate a NumberFormatException
* when parsed by Integer.parseInt or Long.parseLong, e.g. if the value is outside the range
* for int or long respectively.</p>
*
* <pre>
* StringUtils.isNumeric(null) = false
* StringUtils.isNumeric("") = false
* StringUtils.isNumeric(" ") = false
* StringUtils.isNumeric("123") = true
* StringUtils.isNumeric("\u0967\u0968\u0969") = true
* StringUtils.isNumeric("12 3") = false
* StringUtils.isNumeric("ab2c") = false
* StringUtils.isNumeric("12-3") = false
* StringUtils.isNumeric("12.3") = false
* StringUtils.isNumeric("-123") = false
* StringUtils.isNumeric("+123") = false
* </pre>
*
* @param cs the CharSequence to check, may be null
* @return {@code true} if only contains digits, and is non-null
* @since 3.0 Changed signature from isNumeric(String) to isNumeric(CharSequence)
* @since 3.0 Changed "" to return false and not true
*/
public static boolean isNumeric(final CharSequence cs) {
if (isEmpty(cs)) {
return false;
}
final int sz = cs.length();
for (int i = 0; i < sz; i++) {
if (!Character.isDigit(cs.charAt(i))) {
return false;
}
}
return true;
}

一、NumberUtils工具类
org.apache.commons.lang3.math.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);

https://segmentfault.com/a/1190000004922657

Java 数字数组随机数工具类 NumberUtils、ArrayUtils、RandomUtils用法的更多相关文章

  1. java操作数组的工具类-Arrays

    static int binarySearch(type[] a, type key) 使用二分搜索法来搜索key元素在数组中的索引:若a数组不包括key,返回负数.(该方法必须已按升序排列后调用). ...

  2. Java学习关于随机数工具类--Random类

    Random类是伪随机数生成器.之所以称为伪随机数(pseudorandom),是因为它们只是简单的均匀分布序列.Random类定义了以下构造函数: Random() Random(long seed ...

  3. 【Java】字节数组转换工具类

    import org.apache.commons.lang.ArrayUtils; import java.nio.charset.Charset; /** * 字节数组转换工具类 */ publi ...

  4. java.util.Arrays----操作数组的工具类

    java.util.Arrays操作数组的工具类,里面定义了很多操作数组的方法 1.boolean equals(int[] a,int[] b):判断两个数组是否相等. 2.String toStr ...

  5. Java学习-041-颜色工具类(RGB,HEX)

    在日常的网页开发中,经常需要进行颜色数值获取.转换,例如获取红色,获取蓝色,获取绿色,RGB转十六进制颜色,十六进制颜色转RGB等,因而在学习过程中,写了一个小工具类,仅供各位小主参考! 多不闲言,直 ...

  6. Java容器---Arrays & Collections工具类

    1.Array & Arrays 与Collection & Collections区别 (1)Collection": 是一个接口,与其子类共同组成一个Collection ...

  7. Java日期时间实用工具类

    Java日期时间实用工具类 1.Date (java.util.Date)    Date();        以当前时间构造一个Date对象    Date(long);        构造函数   ...

  8. Java线程的并发工具类

    Java线程的并发工具类. 一.fork/join 1. Fork-Join原理 在必要的情况下,将一个大任务,拆分(fork)成若干个小任务,然后再将一个个小任务的结果进行汇总(join). 适用场 ...

  9. Rhino+envjs-1.2.js 在java运行网站js 工具类

    java爬虫遇到个页面加密的东西,找了些资料学习学习 做了个java运行js的工具类,希望对大家有用,其中用到client(获取js)可以自行换成自己的client.主要是用了 Rhino就是Java ...

随机推荐

  1. Sox语音转换的相关知识

    SoX-linux 里操作音频的瑞士军刀 Sox是最为著名的Open Source声音文件 格式转换工具.已经被广泛移植到Dos.windows.OS2.Sun.Next.Unix.Linux等多个操 ...

  2. CF785CAnton and Permutation(分块 动态逆序对)

    Anton likes permutations, especially he likes to permute their elements. Note that a permutation of  ...

  3. 1080 Graduate Admission (30)(30 分)

    It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...

  4. window下的hosts

    存放在windows系统目录中的\system32\drivers\etc下面. hosts文件是用来记录主机ip地址和主机名的对应关系,建立后就可以用主机名来访问主机,而不必记ip地址了.hosts ...

  5. BZOJ2028:[SHOI2009]会场预约(线段树版)

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://www.lydsy.com/JudgeOnline/prob ...

  6. 47: error: undefined reference to `QWebView::QWebView(QWidget*)'

    QT  5.6版本 用Qt界面设计器打开界面文件,在界面上托入QWebView控件,这时运行会出现错误,错误如下: ......... undefined reference to `QWebView ...

  7. SQL一次性插入大量数据【转载】

    在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数据的话,循环使用Insert不仅效率低,而且会导致SQL一系统性能问题.下面介绍SQL Server支持的两种批量 ...

  8. windows下搭建nginx服务器及实现nginx支持https配置流程

    最近刚接触到了tomcat结合nginx做网站的负载均衡.之前对tomcat搭配nginx实现负载均衡也写过,在上一篇的博客中,最近遇到的问题是要在http的基础上支持https.也就是支持加密的请求 ...

  9. Struts2&nbsp;+&nbsp;easyui的DataGrid&nbsp;分页

    jsp页面 js代码: $(function() { $('#ff').hide(); $('#tt').datagrid({ title : '信息显示', iconCls : 'icon-save ...

  10. 有关Linux的.a、.so和.o文件---mark一下(转)

    gcc 生成 .a静态库和 .so动态库   (转载) 我们通常把一些公用函数制作成函数库,供其它程序使用.函数库分为静态库和动态库两种.静态库在程序编译时会被连接到目标代码中,程序运行时将不再需要该 ...