StringToDate日期转换

  • Convert string to date in ISO8601 format

    • 利用LocalDate.parse(CharSequence text) 直接以ISO8601方式格式化
 String originalDate = "2018-08-07";
LocalDate localDate = LocalDate.parse(originalDate);
System.out.println("Date:"+localDate); Output: Date:2018-08-07
  • Convert string to date in custom formats

    • 利用DateTimeFormatter.ofPattern(String pattern)LocalDate.parse(CharSequence text, DateTimeFormatter formatter)结合对日期以指定格式格式化
String originalDate1 = "2018-08-07 10:47:00";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
LocalDate localDate1 = LocalDate.parse(originalDate1,formatter);
System.out.println("custom date:"+localDate1); Output: custom date:2018-08-07

Join Array使用

对现有数组添加字符串组成新的字符串的几个方法:

- String.join(CharSequence delimiter, CharSequence… elements) 场景:可以对现有数组添加分隔符组成新的字符串

String joinedString = String.join(",", "hello", "world", "!");
System.out.println("示例1:" + joinedString); Output: 示例1:hello,world,!
  • String.join(CharSequence delimiter, Iterable elements) 场景:可以对现有列表添加分隔符组成新的字符串
List<String> strList = Arrays.asList("hello", "world", "!");
String joinedString1 = String.join(",", strList);
System.out.println("示例2:" + joinedString1);
Output: 示例2:hello,world,!
  • StringJoiner(CharSequence delimiter) 场景:添加分隔符
 StringJoiner stringJoiner1 = new StringJoiner(",");
stringJoiner1.add("hello").add("world").add("!");
System.out.println("示例3:" + stringJoiner1.toString()); Output: 示例3:hello,world,!
  • StringJoiner(CharSequence delimiter, CharSequence prefix, CharSequence suffix) 场景:添加分隔符以及前后缀
StringJoiner stringJoiner2 = new StringJoiner(",", "[", "]");
stringJoiner2.add("hello").add("world").add("!");
System.out.println("示例4:" + stringJoiner2.toString()); Output: 示例4:[hello,world,!]
  • Collectors.joining 场景:在lambda表达式里面用,针对添加分隔符和前后缀的场景
  List<String> strList1 = Arrays.asList("hello", "world", "!");
String joinedString3 = strList1.stream().collect(Collectors.joining(",","[","]"));
System.out.println("示例5:"+joinedString3); Output: 示例5:[hello,world,!]
  • StringUtils.join() 场景:跟以上用法差不多,使用工具类去把数据和列表组成单独的字符串
String[] strArray = {"hello", "world", "!"};
String joinedString4 = StringUtils.join(strArray, ",");
System.out.println("示例6:" + joinedString4); Output: 示例6:hello,world,!

最新文章

  1. Base64加密算法封装
  2. 分析自定义view的实现过程-实现雪花飞舞效果(转载有改动)
  3. 漫谈Linux内核哈希表(2)
  4. 浅谈输入输出”重定向“——基于Linux系统
  5. js正则表达式实例(汇总)
  6. POJ 1244 Slots of Fun(计算几何)
  7. jquery parent和parents,children和find
  8. javascript使用栈结构将中缀表达式转换为后缀表达式并计算值
  9. 【pku2115-C Looooops】拓展欧几里得-不定方程
  10. mysql时间int日期转换
  11. java并发4-单例设计方法
  12. FreeBsdb FAMP Lamp环境
  13. [Python学习笔记][第五章Python函数设计与使用]
  14. linux查看与开启ssh
  15. c语言贪吃蛇详解3.让蛇动起来
  16. Java-Maven(八):IDEA使用本地maven,并配置远程中央仓库
  17. 转载泡泡机器人——IMU预积分总结与公式推导2
  18. 语义化标签和jQuery选择器
  19. Win7下“回收站已损坏,是否清空该驱动器上的回收站”解决方法
  20. 2292: Quality of Check Digits 中南多校 暴力枚举

热门文章

  1. JavaScript中浅拷贝和深拷贝的区别
  2. HTML和JavaScript代码分离、平稳退化(1)
  3. Flink入门(五)——DataSet Api编程指南
  4. Linux开发环境及应用—《第一、二周单元测验》
  5. nginx优势,依赖,启动
  6. 讲真,这两个IDE插件,可以让你写出质量杠杠的代码
  7. Shell脚本传递带有空格的参数
  8. opencv利用svm训练
  9. python中方法调用和函数调用的区别
  10. python命名空间(namespace)