tostring

How do I print my Java object without getting “SomeType@2f92e0f4”?

跟風遠走 提交于 2019-12-11 19:28:53
问题 I have a class defined as follows: public class Person { private String name; // constructor and getter/setter omitted } I tried to print an instance of my class: System.out.println(myPerson); but I got the following output: com.foo.Person@2f92e0f4 . A similar thing happened when I tried to print an array of Person objects: Person[] people = //... System.out.println(people); I got the output: [Lcom.foo.Person;@28a418fc What does this output mean? How do I change this output so it contains the

How to write a toString method using nodes in java

☆樱花仙子☆ 提交于 2019-12-11 15:32:09
问题 So, I'm not quite sure what is wrong with my toString method. I just keep having an error when I run my tests that it's incorrect. Basically what I am doing is implementing a cyclic DoublyLinkedList data structure. Like a singly linked list, nodes in a doubly linked list have a reference to the next node, but unlike a singly linked list, nodes in a doubly linked list also have a reference to the previous node. Additionally, because the list is "cyclic", the "next" reference in the last node

android studio toString method is not found

半世苍凉 提交于 2019-12-11 14:59:18
问题 i'm working on a project in android studio but when i want to use toString() method it shows : cannot resolve method 'toString()'.please check the image.enter image description here etLPassword = findViewById(R.id.etLPassword); String password = etLPassword.getText().toString(); tostring() appears with red color 来源: https://stackoverflow.com/questions/59119381/android-studio-tostring-method-is-not-found

Why toString() returns an hexadecimal code?

对着背影说爱祢 提交于 2019-12-11 14:12:09
问题 I have this written in my app LastFmServer server = AndroidLastFmServerFactory.getServer(); Artist[] results; results = server.searchForArtist("Hatebreed"); Log.e("", results[2].toString()); Why does this code make this appear in logcat? fm.last.api.Artist@2bf03488 回答1: It's because that class doesn't implement its own toString, so you end up calling the one inherited from java.lang.Object that gives you the class name and its hash. 来源: https://stackoverflow.com/questions/11924018/why

java#tostring

こ雲淡風輕ζ 提交于 2019-12-11 12:48:38
通常使用apache-commons 来生成tostring方法,但是对于类型为java.util.Date的字段打印效果并不是我们想要的。 @Override public String toString() { return ReflectionToStringBuilder.toString(this, ToStringStyle.JSON_STYLE); } 可以自定义style,来解决这个问题,自定义style需要继承org.apache.commons.lang3.builder.ToStringStyle,例如: mport org.apache.commons.lang3.SystemUtils; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; public class MyJsonStyle extends ToStringStyle { private final static

Expression Tree ToString() method generates strange string WHY?

回眸只為那壹抹淺笑 提交于 2019-12-11 12:27:25
问题 I need string conversion of an Expression Tree so I create an Expression Tree and use ToString method like this var exp = ((Expression<Func<UserDetailInfo, bool>>) (x => x.OperationID == operationId)).ToString(); but result is strange x => (x.OperationID == value(TCS.Proxy.PermissionProxy+<>c__DisplayClass5).operationId) TCS.Proxy.PermissionProxy is my class in WCF proxy project !!! (I send expression from client to proxy) but when I create this Expression myself everything is good var entity

Add an object to a JComboBox but show a string without overriding the object's .toString() method

感情迁移 提交于 2019-12-11 12:12:07
问题 The object class that I am working with already has its .toString() method overridden, giving its name. But I am using same object in a JComboBox and I need to display another String. Is there a way to accomplish this? 回答1: You bet there is! What you want to do is to give your JComboBox a custom cell renderer. To do this, you could extending DefaultListCellRenderer making sure to override its getListCellRendererComponent(...) method. Once you've done this, you would call setRenderer(...) on

Why Is ToString() Rounding My Double Value?

喜你入骨 提交于 2019-12-11 11:25:04
问题 How do I prevent my double value from being rounded when converting to a string? I have tried both Convert.ToString and ToString() with the same result. For example my double may look something like 77.987654321 , and the two strings conversions convert to to 77.98765 . I need to keep the precision of the value as is. 回答1: By default the .ToString() method of Double returns 15 digits of precision. If you want the full 17 digits that the double value holds internally, you need to pass the "G17

Java overloading toString() method when array of class is given [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-11 11:24:49
问题 This question already has answers here : How to convert an int array to String with toString method in Java [duplicate] (8 answers) Closed 6 years ago . This is how you overload the toString() method: public class Person extends Object { @Override public final String toString() { Gson gson = new GsonBuilder().serializeNulls().create(); return (gson.toJson(this)); } } In this example I get a JSON string when calling the toString() method of Person instead of the default string representation

Object类的三个常用方法

落花浮王杯 提交于 2019-12-11 10:28:12
getClass()   ·返回对象执行时的Class实例。 toString()   ·将对象返回字符串形式。 equals()   ·比较两个对象是否相等。 可以将getClass() 方法和 toString 方法联合使用。 运算符"==" 比较两个对象的引用是否相等 , 方法 equals() 比较两个对象的实例内容。 来源: https://www.cnblogs.com/Z0320/p/12020649.html