当前位置: 移动技术网 > IT编程>开发语言>Java > ToStringBuilder类的一些心得

ToStringBuilder类的一些心得

2019年07月22日  | 移动技术网IT编程  | 我要评论
今天接触了一下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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网