{"id":65298,"date":"2025-05-03T09:08:25","date_gmt":"2025-05-03T01:08:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65298\/"},"modified":"2025-05-03T09:08:25","modified_gmt":"2025-05-03T01:08:25","slug":"java%e6%80%8e%e4%b9%88%e8%be%93%e5%87%ba%e7%b1%bb%e6%95%b0%e7%bb%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65298\/","title":{"rendered":"java\u600e\u4e48\u8f93\u51fa\u7c7b\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\u8f93\u51fa\u7c7b\u6570\u7ec4\uff1a\u4f7f\u7528 system.out.println() \u65b9\u6cd5\uff1a\u5b83\u4f1a\u8c03\u7528\u7c7b\u7684 tostring() \u65b9\u6cd5\uff0c\u9ed8\u8ba4\u8f93\u51fa\u7c7b\u540d\u548c\u5185\u5b58\u5730\u5740\u3002\u81ea\u5b9a\u4e49\u8f93\u51fa\u683c\u5f0f\uff1a\u8986\u76d6 tostring() \u65b9\u6cd5\uff0c\u5373\u53ef\u81ea\u5b9a\u4e49\u8f93\u51fa\u5185\u5bb9\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111219122454714.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u8f93\u51fa\u7c7b\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u8f93\u51fa\u7c7b\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u8f93\u51fa\u7c7b\u6570\u7ec4<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u7c7b\u6570\u7ec4\u662f\u4e00\u79cd\u5c06\u5bf9\u8c61\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u7684\u6570\u636e\u7ed3\u6784\u3002\u7c7b\u6570\u7ec4\u4e0e\u539f\u59cb\u7c7b\u578b\u7684\u6570\u7ec4\u7c7b\u4f3c\uff0c\u4f46\u5b83\u5b58\u50a8\u7684\u662f\u5bf9\u8c61\u7684\u5f15\u7528\u800c\u4e0d\u662f\u539f\u59cb\u503c\u3002<\/p>\n<p><strong>\u5982\u4f55\u8f93\u51fa\u7c7b\u6570\u7ec4\uff1f<\/strong><\/p>\n<p>\u4f7f\u7528 System.out.println() \u65b9\u6cd5\u6765\u8f93\u51fa\u7c7b\u6570\u7ec4\u3002\u5f53\u4f20\u9012\u4e00\u4e2a\u7c7b\u6570\u7ec4\u65f6\uff0cSystem.out.println() \u4f1a\u8c03\u7528 toString() \u65b9\u6cd5\u3002toString() \u65b9\u6cd5\u9ed8\u8ba4\u8fd4\u56de\u6bcf\u4e2a\u5143\u7d20\u7684\u7c7b\u540d\u548c\u5185\u5b58\u5730\u5740\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>class Student {\n    private String name;\n    private int age;\n\n    public Student(String name, int age) {\n        this.name = name;\n        this.age = age;\n    }\n\n    public String toString() {\n        return \"Student [name=\" + name + \", age=\" + age + \"]\";\n    }\n}\n\npublic class Main {\n    public static void main(String[] args) {\n        Student[] students = {\n                new Student(\"John\", 20),\n                new Student(\"Mary\", 22),\n                new Student(\"Bob\", 25)\n        };\n\n        System.out.println(students);\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre>[Student [name=John, age=20], Student [name=Mary, age=22], Student [name=Bob, age=25]]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u81ea\u5b9a\u4e49\u8f93\u51fa\u683c\u5f0f<\/strong><\/p>\n<p>\u8981\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u7684\u8f93\u51fa\u683c\u5f0f\uff0c\u53ef\u4ee5\u8986\u76d6 toString() \u65b9\u6cd5\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>class Student {\n    \/\/ ...\n\n    public String toString() {\n        return \"Name: \" + name + \", Age: \" + age;\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre>[Name: John, Age: 20, Name: Mary, Age: 22, Name: Bob, Age: 25]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u8f93\u51fa\u7c7b\u6570\u7ec4\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 java \u4e2d\u8f93\u51fa\u7c7b\u6570\u7ec4\uff1a\u4f7f\u7528 system.out.println() \u65b9\u6cd5\uff1a\u5b83\u4f1a\u8c03\u7528\u7c7b\u7684 tostring() \u65b9\u6cd5\uff0c\u9ed8\u8ba4\u8f93\u51fa\u7c7b\u540d\u548c\u5185\u5b58\u5730\u5740\u3002\u81ea\u5b9a\u4e49\u8f93\u51fa\u683c\u5f0f\uff1a\u8986\u76d6 tostring() \u65b9\u6cd5\uff0c\u5373\u53ef\u81ea\u5b9a\u4e49\u8f93\u51fa\u5185\u5bb9\u3002 Java \u4e2d\u8f93\u51fa\u7c7b\u6570\u7ec4 \u5728 Java \u4e2d\uff0c\u7c7b\u6570\u7ec4\u662f\u4e00\u79cd\u5c06\u5bf9\u8c61\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u7684\u6570\u636e\u7ed3\u6784\u3002\u7c7b\u6570\u7ec4\u4e0e\u539f\u59cb\u7c7b\u578b\u7684\u6570\u7ec4\u7c7b\u4f3c\uff0c\u4f46\u5b83\u5b58\u50a8\u7684\u662f\u5bf9\u8c61\u7684\u5f15\u7528\u800c\u4e0d\u662f\u539f\u59cb\u503c\u3002 \u5982\u4f55\u8f93\u51fa\u7c7b\u6570\u7ec4\uff1f \u4f7f\u7528 System.out.println() \u65b9\u6cd5\u6765\u8f93\u51fa\u7c7b\u6570\u7ec4\u3002\u5f53\u4f20\u9012\u4e00\u4e2a\u7c7b\u6570\u7ec4\u65f6\uff0cSystem.out.println() \u4f1a\u8c03\u7528 toString() \u65b9\u6cd5\u3002toString() \u65b9\u6cd5\u9ed8\u8ba4\u8fd4\u56de\u6bcf\u4e2a\u5143\u7d20\u7684\u7c7b\u540d\u548c\u5185\u5b58\u5730\u5740\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u793a\u4f8b\u4ee3\u7801\uff1a class Student { private String name; private int age; public Student(String name, int age) { this.name = name; this.age = age; } public String toString() { return &#8220;Student [name=&#8221; + name [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-65298","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65298","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=65298"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65298\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}