了解java的这些功能可让你少走不少弯路

日常工做中的一些现成的方法能够减小咱们不少的工做时间,下面只是我总结的一小部分经常使用的类和方法,我会接着发~java

文末有余胜军老师的学习视频链接你们感兴趣的能够下载下来看看
git


BeanUtils 类中的方法:
web

public static Map describe(Object bean)windows

英文解释:Return the entire set of properties for which the specified bean provides a read methodapi

用处:将java 对象中的属性以及值转换为map,注意返回的map中包含了类信息,若是不须要能够直接remove掉"class"浏览器


public static void populate(Object bean, Map properties)网络

英文解释:Populate the JavaBeans properties of the specified bean, based on the specified name/value pairs.ide

用处:把指定的键值对填充到指定的java 对象中。跟describe方法正好是反过来的。工具


public static String getNestedProperty(Object bean, String name)学习

英文解释:Return the value of the (possibly nested) property of the specified name, for the specified bean, as a String.

嵌套属性访问。使用这种方法,你将访问路径上的属性的名称用“.”拼接起来

例如getNestedProperty(test,"test1.test2.test3");经过这个方法可以直接获取test对象下test1属性下的test2属性下的test3属性

固然若是中间路径写错会报异常。


StringUtils.getFilename(filname) 获取文件名

注释:

Unix使用斜杆/ 做为路径分隔符,而web应用最新使用在Unix系统上面,因此目前全部的网络地址都采用 斜杆/ 做为分隔符。

Windows因为使用 斜杆/ 做为DOS命令提示符的参数标志了,为了避免混淆,因此采用 反斜杠\ 做为路径分隔符。因此目前windows系统上的文件浏览器都是用 反斜杠\ 做为路径分隔符。随着发展,DOS系统已经被淘汰了,命令提示符也用的不多


大小写转换,空格不动:

StringUtils.swapCase(String str); 

StringUtils.capitalize(String str); 首字母大写

StringUtils.uncapitalize(String str);首字母小写

StringUtils.isAlphanumericSpace(String str); 只由字母数字和空格组成

StringUtils.isAlphaspace( str); 若是str全由字母或空格组成返回True.

StringUtils.isNumeric( str); 若是str全由数字组成返回True.

StringUtils.isAlpha( str); 若是str全由字母组成返回True.

StringUtils.isNumeric( str); 若是str全由数字组成返回True.

StringUtils.isNumericSpace(String str); 只由数字和空格组成

StringUtils.abbreviate(str,width); 

StringUtils.abbreviate(str,offset,width);

在给定的width内取得str的缩写,当testString的长度小于width则返回原字符串.  缩写的形式为…is a test…


字符串转数据或者判断字符串是不是数字经常使用工具类NumberUtils

NumberUtils.isNumber(String str) 判断是否为数字

NumberUtils.isDigits(String str) 判断是不是整数


SystemUtils----获取系统信息(原理都是调用System.getProperty())

SystemUtils.getJavaHome()

SystemUtils.getJavaIoTmpDir()

SystemUtils.getUserDir()

SystemUtils.getUserHome()

SystemUtils.JAVA_VERSION

SystemUtils.OS_NAME

SystemUtils.USER_TIMEZONE

相关文章
相关标签/搜索