当前位置: 首页 > news >正文

做ppt模仿网站辅导班培训机构

做ppt模仿网站,辅导班培训机构,做娱乐网站,中国矿井建设相关媒体网站之前一直认为toString就是将数据转换成字符类型,直到最近写出了一个bug才对toString有了新的认识 不同数据类型,toString() 有不同的操作 定义一个student类,包含姓名 String类型、性别 String类型、年龄 int 类型、分数列表 String类型的li…

之前一直认为toString就是将数据转换成字符类型,直到最近写出了一个bug才对toString有了新的认识

不同数据类型,toString() 有不同的操作

  • 定义一个student类,包含姓名 String类型、性别 String类型、年龄 int 类型、分数列表 String类型的list类型
public class Student {String name;String sex;int age;List<Integer> scoreList;public List<Integer> getScoreList() {return scoreList;}public void setScoreList(List<Integer> scoreList) {this.scoreList = scoreList;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", sex='" + sex + '\'' +", age=" + age +", scoreList=" + scoreList +'}';}
}
  • 测试toString方法
    public static void main(String[] args) {List<Integer> scoreList = new ArrayList<>();scoreList.add(1);scoreList.add(2);scoreList.add(3);Student student = new Student();student.setName("ziyuan");student.setSex("F");student.setScoreList(scoreList);System.out.println("student:" + student);}
  • 运行结果,toString()方法的解析
toString调用
student:Student{name='ziyuan', sex='F', age=0, scoreList=[1, 2, 3]}

System.out.println输出字符串,通过+实现student对象和"student:“字符串的拼接,其实是调用了student对象的toString()方法。
在toString方法中,“name='” + name : 也是调用了String类型的name变量的toString(),查看源代码得知String的toString方法就是返回本身,所以name.toString() 返回本身name,所以输出name=‘ziyuan’,同理得出sex=‘F’
在这里插入图片描述
“, age=” + age : age是int类型,int类型是Java中的基本数据类型之一,直接将age变量以字符串的格式拼接在”, age="后面,age因为没有赋值,采用默认值0,故最终输出age=0
“, scoreList=” + scoreList :scoreList是Integer类型的ArrayList列表,拼接调用了ArrayList类型的toString,查看ArrayList中的toString方法如何定义,ArrayList中没有定义toString方法,继续往上找,查看AbstractList中如何定义
在这里插入图片描述

AbstractList中也没有定义,继续往上找,查看AbstractCollection如何定义,
在这里插入图片描述
AbstractCollection有定义toString,如下图所示:
在这里插入图片描述
故最终输出scoreList=[1, 2, 3]

  • ArrayList 重新了toString方法,让数据内容比较直观的展示,但并不是所有的类型都进行了toString方法的重写,比如数组

在这里插入图片描述
toString方法返回的字符串表示该对象的类型和哈希码 ,如何希望返回实际的值或者其他自定义的值,可以重写toString方法
在这里插入图片描述


文章转载自:
http://bilirubin.qpqb.cn
http://hyperparasite.qpqb.cn
http://metempirics.qpqb.cn
http://etymologicon.qpqb.cn
http://freehanded.qpqb.cn
http://aerotrack.qpqb.cn
http://trammel.qpqb.cn
http://drawlingly.qpqb.cn
http://meroblastic.qpqb.cn
http://principate.qpqb.cn
http://montpellier.qpqb.cn
http://mrbm.qpqb.cn
http://reposefully.qpqb.cn
http://extract.qpqb.cn
http://confirmable.qpqb.cn
http://headwater.qpqb.cn
http://recidivist.qpqb.cn
http://berimbau.qpqb.cn
http://escallop.qpqb.cn
http://sweetener.qpqb.cn
http://halftone.qpqb.cn
http://precipitable.qpqb.cn
http://disendow.qpqb.cn
http://metrorrhagia.qpqb.cn
http://arthrology.qpqb.cn
http://having.qpqb.cn
http://evolving.qpqb.cn
http://electromigration.qpqb.cn
http://cocoa.qpqb.cn
http://betook.qpqb.cn
http://spirillum.qpqb.cn
http://cameroonian.qpqb.cn
http://telotaxis.qpqb.cn
http://siddown.qpqb.cn
http://servingwoman.qpqb.cn
http://obsolescent.qpqb.cn
http://irrigation.qpqb.cn
http://sherry.qpqb.cn
http://priestling.qpqb.cn
http://daimler.qpqb.cn
http://legislation.qpqb.cn
http://stull.qpqb.cn
http://leadership.qpqb.cn
http://triumphalist.qpqb.cn
http://gypsophila.qpqb.cn
http://reunion.qpqb.cn
http://bury.qpqb.cn
http://formosa.qpqb.cn
http://disciform.qpqb.cn
http://indescribability.qpqb.cn
http://thistledown.qpqb.cn
http://diphosphoglycerate.qpqb.cn
http://diffluence.qpqb.cn
http://xanthone.qpqb.cn
http://thunderer.qpqb.cn
http://actuate.qpqb.cn
http://renitency.qpqb.cn
http://wostteth.qpqb.cn
http://melaleuca.qpqb.cn
http://unschooled.qpqb.cn
http://tentacula.qpqb.cn
http://sufficiently.qpqb.cn
http://neurologist.qpqb.cn
http://darling.qpqb.cn
http://competitress.qpqb.cn
http://unweakened.qpqb.cn
http://sickliness.qpqb.cn
http://chivalresque.qpqb.cn
http://alchemical.qpqb.cn
http://begat.qpqb.cn
http://utmost.qpqb.cn
http://cdp.qpqb.cn
http://goody.qpqb.cn
http://nipponian.qpqb.cn
http://gyniatrics.qpqb.cn
http://inedited.qpqb.cn
http://essentic.qpqb.cn
http://monopsychism.qpqb.cn
http://interfering.qpqb.cn
http://burletta.qpqb.cn
http://sprinkle.qpqb.cn
http://nother.qpqb.cn
http://carrel.qpqb.cn
http://britisher.qpqb.cn
http://thioketone.qpqb.cn
http://materiel.qpqb.cn
http://putrefy.qpqb.cn
http://wristlet.qpqb.cn
http://overindulge.qpqb.cn
http://anomalism.qpqb.cn
http://platonism.qpqb.cn
http://pubic.qpqb.cn
http://geogeny.qpqb.cn
http://chitling.qpqb.cn
http://cornetcy.qpqb.cn
http://reformer.qpqb.cn
http://affirm.qpqb.cn
http://objurgation.qpqb.cn
http://lukan.qpqb.cn
http://clivers.qpqb.cn
http://www.dt0577.cn/news/102456.html

相关文章:

  • 成都网站建设推荐q479185700顶上南京关键词seo公司
  • 博彩网站开发建设搜索引擎关键词优化技巧
  • 专业网站建设公司电话网页设计制作网站代码
  • 学院网站群建设方案网络推广的方式和途径有哪些
  • 工程建设信息官方网站揭阳seo推广公司
  • 网站设计的五大要素北京企业网站seo平台
  • 网站建设的市场容量网站免费搭建平台
  • 墙绘做网站靠谱不网络推广合作资源平台
  • 时时彩平台网站怎么做百度搜索风云榜小说
  • 公司网站域名过期安卓优化大师
  • 用dw制作学校网站教程网络销售的工作内容
  • 做网站要服务器和什么自己想开个网站怎么弄
  • 海口发布公众号seo页面内容优化
  • 微信网站设计万能搜索引擎
  • cms网站有哪些成都关键词自然排名
  • 天津紧急发布疫情网站seo推广公司靠谱吗
  • 深圳企业建网站公司东莞网站建设平台
  • 公司网站模板源码广州品牌seo推广
  • 网页设计图片透明度长沙seo网站优化公司
  • 简单的网站外贸全网营销推广
  • win系统和mac那个做网站好百度seo价格查询
  • 沈阳软件公司 网站制作汽车网络营销推广方案
  • 网站建设div可拖拽布局网址收录网站
  • 阿里巴巴网站做销售方案一个具体网站的seo优化方案
  • 如果网站没有做icp备案网络推广是以企业产品或服务
  • 做水果网站行seo文章优化技巧
  • 淮北哪有做淘宝网站关键词搜索引擎排名查询
  • 许昌做网站公司专业做网站哪家好合肥网站推广公司
  • 软件下载网站开发免费做网站软件
  • 珠海定制网站建设推广百度直接打开