ToStringBuilder类的一些心得
时间:2022-10-10 04:02:27
今天接触了一下ToStringBuilder类,这里做一个备忘。
ToStringBuilder在包 common-lang 中,主要用于一个类的格式化输出。ToStringBuilder类中的append方法可以向该类添加基本类型、数组和对象 ,只有添加的方法才会被toString方法输出。
ToStringStyle类则是对输出的内容进行格式化。
例如:
public String toString() …{
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append(『name』, name)
.append(『age』, age)
.toString();
}
ToStringStyle参数说明:
1. DEFAULT_STYLE
Person@182f0db[name=John Doe,age=33,smoker=false]
2. MULTI_LINE_STYLE
Person@182f0db[
name=John Doe
age=33
smoker=false
]
3. NO_FIELD_NAMES_STYLE
Person@182f0db[John Doe,33,false]
4. SHORT_PREFIX_STYLE
Person[name=John Doe,age=33,smoker=false]
5. SIMPLE_STYLE
John Doe,33,false
标签:ToStringBuilder
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java设计模式之工厂模式实现方法详解
2023-11-26 07:55:51
IDEA快速搭建spring boot项目教程(Spring initializr)
2023-08-17 21:11:16
![](https://img.aspxhome.com/file/2023/0/58060_0s.png)
Android Flutter使用本地数据库编写备忘录应用
2023-09-15 17:24:09
![](https://img.aspxhome.com/file/2023/6/109226_0s.webp)
IDEA解决springboot热部署失效问题(推荐)
2023-08-12 10:40:49
![](https://img.aspxhome.com/file/2023/8/58148_0s.png)
深入理解Java中的接口
2023-11-08 23:52:43
java代码执行字符串中的逻辑运算方法
2023-11-29 12:13:06
java实现新浪微博Oauth接口发送图片和文字的方法
2023-11-29 01:43:04
spring mvc中@RequestBody注解的作用说明
2022-04-07 14:15:02
![](https://img.aspxhome.com/file/2023/4/62764_0s.png)
C#获取网页源代码的方法
2023-06-19 05:43:44
springboot实现在工具类(util)中调用注入service层方法
2021-06-17 20:02:51
![](https://img.aspxhome.com/file/2023/6/60616_0s.png)
深度解析Java中ArrayList的使用
2023-06-16 23:26:01
![](https://img.aspxhome.com/file/2023/6/60696_0s.png)
新手小白学JAVA IDEA下载使用手册全集
2023-11-23 14:33:23
![](https://img.aspxhome.com/file/2023/3/59773_0s.jpg)
解决ThingsBoard编译报错问题:Failure to find org.gradle:gradle-tooling-api:jar:6.3
2021-11-20 16:24:22
![](https://img.aspxhome.com/file/2023/7/62117_0s.png)
详解Java中的时区类TimeZone的用法
2023-11-29 02:03:09
java selenium使用浏览器调试工具实现方法
2023-07-27 04:04:22
![](https://img.aspxhome.com/file/2023/7/57897_0s.gif)
Java spring AOP基础
2022-08-10 12:39:25
React-Native之Android(6.0及以上)权限申请详解
2023-07-28 01:56:55
![](https://img.aspxhome.com/file/2023/8/85998_0s.jpg)
Spring整合Quartz实现定时任务调度的方法
2023-07-07 00:55:55
浅析Java多线程同步synchronized
2023-05-20 15:52:29
C#几种截取字符串的方法小结
2023-07-16 09:55:10