赞
踩
新晋JAVA领域创作者:后端三郎
优质博客持续输出,代码撸起来
目录
collectionToCommaDelimitedString方法
commaDelimitedListToStringArray方法
splitArrayElementsIntoProperties方法
- /**
- * @Description:addStringToArray方法
- * @Author:ZhaoYaJun
- * @Date:2022/03/01
- * @explain:追加特定的字符串给特定的String数组,返回一个新的数组
- */
- String[] name ={"张三"};
- String[] addStringToArray = StringUtils.addStringToArray(name, "李四");
- for (int i = 0; i < addStringToArray.length; i++) {
- System.out.println(addStringToArray[i]);
- }
-
- 输出结果:
- 张三
- 李四
- /**
- * @Description:delete方法
- * @Author:ZhaoYaJun
- * @Date:2022/03/01
- * @explain:删除字符串中指定的字符串
- */
- String delete = StringUtils.delete("张三", "三");
- System.out.println("delete方法结果:"+delete);
-
- 输出结果:
- delete方法结果:张
- /**
- * @Description:replace方法
- * @Author:ZhaoYaJun
- * @Date:2022/03/01
- * @explain:把字符串中所有的张三替换为三郎
- */
- String replace = StringUtils.replace("张三李四王五张三", "张三", "三郎");
- System.out.println("replace方法结果:"+replace);
-
- 输出结果:
- replace方法结果:三郎李四王五三郎
- /**
- * @Description:split方法
- * @Author:ZhaoYaJun
- * @Date:2022/03/01
- * @explain:通过逗号把字符串分割成一个数组
- */
- String[] split = StringUtils.split("张三,王五",",");
- for (int i = 0; i < split.length; i++) {
- System.out.println(split[i]);
- }
-
- 输出结果:
- 张三
- 王五
- /**
- * @Description:applyRelativePath方法
- * @Author:ZhaoYaJun
- * @Date:2022/03/01
- * @explain:通过第一个文件的全路径,返回第二个文件的全路径
- */
- String applyRelativePath = StringUtils.applyRelativePath("d:/workspace/4188/Sentinel-1.8.3.zip", "sentinel-dashboard-1.8.3.jar");
- System.out.println(applyRelativePath);
-
- 输出结果:
- d:/workspace/4188/sentinel-dashboard-1.8.3.jar
- /**
- * @Description:arrayToCommaDelimitedString方法
- * @Author:ZhaoYaJun
- * @Date:2022/03/01
- * @explain:将String数组转换为逗号分隔的字符串
- */
- String[] sex ={"男人","女人"};
- String arrayToCommaDelimitedString = StringUtils.arrayToCommaDelimitedString(sex);
- System.out.println("arrayToCommaDelimitedString方法结果是:"+arrayToCommaDelimitedString);
-
- 输出结果:
- arrayToCommaDelimitedString方法结果是:男人,女人
- /**
- * @Description:arrayToDelimitedString方法
- * @Author:ZhaoYaJun
- * @Date:2022/03/01
- * @explain:将String数组转换为指定分隔符分隔的字符串
- */
- String[] model = {"用户","美食"};
- String arrayToDelimitedString = StringUtils.arrayToDelimitedString(model,"%");
- System.out.println("arrayToDelimitedString方法结果是:"+arrayToDelimitedString);
-
- 输出结果:
- arrayToDelimitedString方法结果是:用户%美食
- /**
- * @Description:capitalize方法
- * @Author:ZhaoYaJun
- * @Date:2022/03/01
- * @explain:将字符串第一个字母转为大写
- */
- String capitalize = StringUtils.capitalize("san");
- System.out.println("capitalize方法结果是:"+capitalize);
-
- 输出结果:
- capitalize方法结果是:San
- /**
- * @Description:cleanPath方法
- * @Author:ZhaoYaJun
- * @Date:2022/03/01
- * @explain:返回一个规范化路径,去除了例../这种的语法
- */
- String cleanPath = StringUtils.cleanPath("d:/workspace/4188/../新建文本文档.txt");
- System.out.println("cleanPath方法结果是:"+cleanPath);
-
- 输出结果:
- cleanPath方法结果是:d:/workspace/新建文本文档.txt
- /**
- * @Description:collectionToCommaDelimitedString方法
- * @Author:ZhaoYaJun
- * @Date:2022/03/01
- * @explain:将list集合转为逗号分割的字符串
- */
- List<String> nameList = new ArrayList<String>(){
- {add("张三");add("李四");}};
- String collectionToCommaDelimitedString = StringUtils.collectionToCommaDelimitedString(nameList);
- System.out.println("collectionToCommaDelimitedString方法结果是:"+collectionToCommaDelimitedString);
-
- 输出结果:
- collectionToCommaDelimitedString方法结果是:张三,李四
- /**
- * @Description:collectionToDelimitedString方法
- * @Author:ZhaoYaJun
- * @Date:2022/03/03
- * @explain:按照指定的字符将集合分割为字符串
- */
- List<String> typeList = new ArrayList<String>(){
- {add("用户");add("美食");}};
- String collectionToDelimitedString = StringUtils.collectionToDelimitedString(typeList, "%");
- System.out.println("collectionToDelimitedString方法结果是:"+collectionToDelimitedString);
- /*重载--参数不同-以什么开头以什么结尾*/
- String collectionToDelimitedStrings = StringUtils.collectionToDelimitedString(typeList, "%", "开头", "结尾");
- System.out.println("collectionToDelimitedStrings方法结果是::"+collectionToDelimitedStrings);
-
- 输出结果是:
- collectionToDelimitedString方法结果是:用户%美食
- collectionToDelimitedStrings方法结果是::开头用户结尾%开头美食结尾
- /**
- * @Description:commaDelimitedListToSet方法
- * @Author:ZhaoYaJun
- * @Date:2022/03/03
- * @explain:将逗号分隔的字符串转为set集合
- */
- Set<String> commaDelimitedListToSet = StringUtils.commaDelimitedListToSet("张三,李四");
- for (String c : commaDelimitedListToSet) {
- System.out.println(c);
- }
-
- 输出结果是:
- 张三
- 李四
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。