场景:
1.使用list的时候需要判断是否为null,同时是否为空
2.使用String的时候我们需要判断是否为null,同时是否为空
3.随机数,随机字符串
代码:
String t=null; if(t==null ||"".equals(t)){ //do }
list的操作
List<String> list=null; if(list==null ||list.isEmpty()){ //do }
方案:
我们可以采用apache下的common进行常用的操作
import org.apache.commons.collections.*; import org.apache.commons.lang.*;
对字符串的操作:
private static void stringTest() { String str = null; System.out.println(StringUtils.isEmpty(str)); str = ""; System.out.println(StringUtils.isEmpty(str)); System.out.println(StringUtils.trim(null)); System.out.println(StringUtils.split(null, "&|")); System.out.println(ArrayUtils.toString(StringUtils.split("id=4&type=1", "&|="))); }
对collection的操作:
private static void collectionTest() { System.out.println(CollectionUtils.isEmpty(null)); System.out.println(CollectionUtils.isEmpty(ListUtils.EMPTY_LIST)); }
对number的操作:
private static void numberTest() { System.out.println(NumberUtils.isDigits(null)); System.out.println(NumberUtils.isDigits("00052")); System.out.println(NumberUtils.isDigits("000.52")); System.out.println(NumberUtils.isNumber("0.0052")); System.out.println(NumberUtils.isNumber(null)); }
对random的操作:
private static void randomTest() { System.out.println(RandomUtils.nextInt(10)); System.out.println(RandomUtils.nextBoolean()); System.out.println(RandomUtils.nextLong()); }
对randomstring的操作:
private static void randomStringTest() { System.out.println(RandomStringUtils.randomAlphabetic(100)); System.out.println(RandomStringUtils.random(10, "abc")); }
相关推荐
Apache common io转码工具类入门教程
Java通过Apache提供的Commons Email工具类实现邮箱发送验证码功能,代码附详细注释文本,实现方法中附有验证码生成方法
这个压缩文件里面汇集了常用的apache commoms工具类
Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动。最齐全的Commons.jar包
Apache common-Collection提供的工具类 JDK提供的工具类 Arrays Collections Objects Arrays是操作数组对象的工具类 Collections是操作集合对象的工具类 Objects是操作引用数据类型对象的工具类 Arrays的常用方法 ...
apache开源项目源码commons-proxy-...各种代理模式操作的工具类源码以及代理模式案例源码,你会从中得到意想不到的效果! apache开源组织开发的开源项目源码,其优良的代码风格和高质量的源码是学习者难得的学习资料!
apache开源项目源码commons-el-1.0-src ...各种el表达式操作工具类源码,你会从中得到意想不到的效果! apache开源组织开发的开源项目源码,其优良的代码风格和高质量的源码是学习者难得的学习资料!
Commons-Lang 提供了许多许多通用的工具类集,提供了一些java.lang中类的扩展功能 Latka Commons-Latka 是一个HTTP 功能测试包,用于自动化的QA,验收和衰减测试. Launcher Launcher 组件是一个交叉平台的Java 应用...
commons-lang3.3.1.jar、Apache Commons包中的一个,包含了一些数据类型工具类,是java.lang.*的扩展。必须使用的jar包。为JRE5.0+的更好的版本所提供 Jar文件包含的类: META-INF/MANIFEST.MFMETA-INF/LICENSE....
使用apache的common-net.jar,实现ftp文件的上传和下载,封装成工具类,方便开发。
对字符串进行编解码,Apache Commons家族中的Commons Codec就提供了一些公共的编解码实现,比如Base64, Hex, MD5,Phonetic and URLs等等。
java 工具类 lang3 jar包 StringUtils ArrayUtils SystemUtils
常用工具jar包详解 ,包括apache的 common 包,有源码
一个简单的开源Android工具类库,提供许多常用的类帮助我们开发程序。 AndroidCommon 一个简单的开源Android工具类库,提供许多常用的类帮助我们开发程序。 These are the Android Common Utils. Class ...
四、线程相关工具类 1、com.baijob.commonTools.thread.BaseRunnable 此类实现了Runnable接口,扩展了功能。 增加名称、ID,调用次数和时间统计、线程停止接口等,并且在线程运行时,不允许此线程第二次启动。 2、...
├─28个java常用的工具类 │ │ Base64.java │ │ Base64DecodingException.java │ │ CConst.java │ │ CharTools.java │ │ ConfigHelper.java │ │ Counter.java │ │ CTool.java │ │ DateHandler.java ...
经常对MongoDB进行一些常用操作,为了方便起见将这些常用操作合并到一个工具类中,方便自己开发使用。 没用Spring Data、Morphia等框架是为了减少学习、维护成本,另外自己直接JDBC方式的话可以更方便的控制操作...
公开的APIevents 表示EventEmitter特殊实例,旨在将事件发布到cordova-lib和cordova-cli 用法: const { events } = require ( 'cordova-common' ) ;events . emit ( 'warn' , 'Some warning message' ) 以下是...
依赖与ApacheCommon的Java通用工具工程类概览: ArrayUtil -----> ArrayUtil通用工具类BrowserUtil ----->浏览器通用工具类ClassLoaderUtil ----->类加载通用工具类ClassUtil ----->类通用工具类...
HttpClient 是Apache Jakarta Common 下的子项目,可以用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端编程工具包,并且它支持 HTTP 协议最新的版本和建议