[Solved] How do I return/implement the toString for the ArrayList? Also, just want to check that I’ve correctly created my objects?

You have a lot of error in your code : First Don’t ever name your variables with Upper letter in beginning, java use camelCase Second Don’t declare your variable with private public in your method. private ArrayList<Object> List = new ArrayList<Object>(); Third You can’t declare a method inside another method you have to close the … Read more

[Solved] Overload a toString Method

First of all, toString method comes from object class, don’t try to make multiple of those methods or anything like that, have everything in one method. As to your problem, you can make a variable String description for your class, and initialize it in constructor and then in toString just return that variable. You can … Read more

[Solved] How to write a toString() method that should return complex number in the form a+bi as a string? [closed]

You can override toString() to get the desired description of the instances/classes. Code: class ComplexNum { int a,b; ComplexNum(int a , int b) { this.a = a; this.b = b; } @Override public String toString() { return a + “+” + b + “i”; } public static void main(String[] args) { ComplexNum c = new … Read more

[Solved] ToString on Object generate error

It seems as if the reason you’re getting an error is because the userReadables is initially set to a null string. in the catch, you have catch(Exception e) { userReadables = null; } and since the userReadables is already null, it’s calling the Exception before it does anything else. Make it something related to the … Read more

[Solved] calculate the length of line using toString

The toString() method of the Point class should look like: public String toString() { return “(” + x + “,” + y + “)”; } The toString() method of the Line class should look like (supposing you have two members of type Point in the class Line): public String toString() { return “(” + point_A.getX() … Read more

[Solved] How to override `toString()` properly to get rid of hash code

You are calling toString() on ComputableLiveData, you have to call toString() on myEntities which will in turn call toString() on the individual elements which are MyEntity. myViewModel.getAllData().observe( this, new Observer<List<MyEntity>>() { @Override public void onChanged(@Nullable List<MyEntity> myEntities) { Log.d(“TAG: “, “DATA CHANGED! ” + myEntities.toString()); } }); 1 solved How to override `toString()` properly to … Read more