Common lang一些边界方法总结(好记性不如烂笔头,需要慢慢积累).一定要利用好现有的轮子,例如Apache common与Google Guava

好记性真是不如烂笔头啊!!!!

如下代码:

  List<String> list = new ArrayList<String>();
        list.add("1");
        list.add("2");
        list.add("3");
        System.out.println(list.toString());
        System.out.println(StringUtils.strip(list.toString(),"[]"));
        System.out.println(StringUtils.strip("ab122122abc121bca","abc"));

输出:

[1, 2, 3]
1, 2, 3
122122abc121

  

通过输出就可以看出只要str的开始与结束的字符是stripChars中的话则就删除。

apache common collections :

<!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
<dependency>
    <groupId>commons-collections</groupId>
    <artifactId>commons-collections</artifactId>
    <version>3.2.1</version>
</dependency>

  

最近写代码使用到反射,是自己使用jdk基础类库实现,虽然自己实现的代码相对也比较简装没有什么bug,但是代码量和代码优雅程序还是不如直接使用现有类库来的简单粗暴。当然也不能把类库当做黑盒使用,有时间还是要做看看源码了解一下实现思路。在代码编写时想到了之前用过的工具类:

<!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
<dependency>
    <groupId>commons-beanutils</groupId>
    <artifactId>commons-beanutils</artifactId>
    <version>1.9.3</version>
</dependency>

  多积累多实用 多看源码

原文地址:https://www.cnblogs.com/leodaxin/p/9082973.html