String类作为中间量在各类中的转换

String类作为中间量在各类中的转换

原因:由于objects是各类的直接或间接父类,而它带有toString方法 所以在不同对象进行转换时,String类具有巨大的潜在作用

1.字符数组与字符串的相互转换

String a="abc";
  char[] charArray = a.toCharArray();
  String b=new String(charArray);

2.BigInteger BigDecimal的构造方法

BigInteger bigInteger = new BigInteger("1234567890");
  BigDecimal bigDecimal = new BigDecimal("1324432.131321");

3.正则表达式

String s="\\w{12,14}";
String s2="213453421";
boolean matches = s2.matches(s);
System.out.println(matches);

4.时间与时间的格式化

  LocalDateTime localDateTime = LocalDateTime.now();
  LocalDateTime  birthday=LocalDateTime.of(2020,12,15,12,0);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  String format = formatter.format(birthday);
  System.out.println(format);
posted @ 2025-01-26 09:50  懒洋洋血洗青青草原  阅读(26)  评论(0)    收藏  举报