Questions tagged [tostring]

"toString" or "ToString" is a major formatting method or function used in high level programming languages. It converts an Object to its string representation so that it is suitable for display.

toString() is a function which can be overridden.

toString

The toString() method is widely used to represent objects as human-readable text and practically every class should implement it. Usually it is very simple: generated string contains the object type and lists values of the most important fields. That's why process of writing such methods can easilly be automated. Eclipse, as the best java IDE in the world, should include functionality of automatic toString() method generation to make its users lives even simpler. Implementing it is the aim of this project.

Java represents this as the toString() method where C# represents it as ToString().

2528 questions
0
votes
0 answers

Continuously getting java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

i am getting the following error when i try to debug the app, app is running without a crash but unable to load another location on map, W/System.err: org.json.JSONException: Index 0 out of range [0..0) W/System.err: at…
0
votes
2 answers

UnknownFormatConversionException: Conversion = ' '

First, thank you for spending some time on this problem. I've tried based on my own knowledge but can not find out where to modify. I have made a game and in the end, I have to return the formatted string to the terminal. The exception appeared when…
Woden
  • 1,054
  • 2
  • 13
  • 26
0
votes
2 answers

Printing Objects in an ArrayList

The project requires me to create an ArrayList of objects and then print the complete list. Additionally the maximum amount of characters cannot exceed 280. The objects created are defined in my "Message" class and the lists are defined and…
0
votes
2 answers

Drupal 8 Url::FromRoute toString() Don't take the braces

I would like to recover a road with URL::FromRoute Except that I have some concerns when I use to toString $path = Url::fromRoute('my_route_name',['mypParamsId' => 'MYPARAMSID'])->toString(); In this way I find a road but it's not the right one I…
0
votes
3 answers

Is it possible to recover a parent class's overridden method?

I'm playing around with objects right now and noticed something when I override toString() for readability. Observe these classes and the results. class Point { int x; int y; Point(int x, int y) { this.x = x;…
0
votes
1 answer

toString of lambda expressions in c++?

Is there any way to print a C++ lambda expression and see a textual representation of the function it represents? Here is a simple example showing what I mean: #include #include const char *toString(const…
OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87
0
votes
0 answers

Is there a way of printing the hashcode value with use of (toString)

import java.io.*; import java.util.*; class Student implements Comparable{ String name; int rno; Student(String name, int rno){ this.name = name; this.rno = rno; } // end of constructor public boolean equals(Object o){ Student…
Swapnil Padaya
  • 687
  • 5
  • 14
0
votes
2 answers

toString() in JavaScript: why does toString() still get called since a valueOf() prototype for type conversion of object to number

let obj = { toString() { return "2"; } }; let n = +obj; alert(n); Since +obj requires a number, shouldn't it use the valueOf() prototype for type conversion which returns the object. Instead it uses the toString() method and…
Israel
  • 77
  • 7
0
votes
1 answer

Java creating objects for every record with unique ID

I'm working on this project where I am supposed to parse the file which contains data of fictional companies and other relevant details, create an object for each record and store objects into a suitable collection. I have made a start but now I'm…
sevd
  • 7
  • 5
0
votes
5 answers

How to change an arrays into a String with each name on a separate line in java?

I am a newbie to java and I am trying to begin with a simple task- list a group of names into alphabetical order. Currently, my code is fine: import java.util.Arrays; public class CLASSROOM_SSONG { String[] names = {"Joe", "Bob", "Andy"}; …
Darkrai33
  • 51
  • 7
0
votes
2 answers

How to access variables inside an object?

I am creating an algorithm to fill up a train with animals based on their size and type. Imagine an animal object in an animal class with a type and size. /* 0 = Carnivore, Carnivores will eat other animals which are smaller or the same size. * 1 =…
user12426245
0
votes
1 answer

What is .toString doing in this parameter- vehicle.toString+"firstImage"

Just starting out with scala and gatling. I am trying to understand code written by another team member. The code is: UploadFile.uploadFile(vehicle.toString+"firstImage", sessionHeaders, ImagePath,vehicle.toString); uploadFile is a method in…
RenukaA
  • 25
  • 1
  • 8
0
votes
2 answers

ToString override to return array

I wanted to make a wpf program that when you click the Generate button the class SSales will get/store the arrays of values to the class then return it to the listbox. New here. Sorry. private void GenerateButton_Click(object sender, EventArgs…
0
votes
1 answer

How would I get this debug call to print out the actual values of the object?

I understand that Arrays.sort() has a void return type, and that toArray() has return type is an object, so I did an override by passing in the object that I wanted to see. How can I see the contents of my Time object? Sorry if this is a…
0
votes
2 answers

Is it good practice to use ToString() to convert a number directly to a string?

Is it good practice to convert a number to a string directly using ToString()? Like this: string numStr = 0.ToString(); Or should the number be entered into an int variable first and then use ToString() on that? Like this: int num = 0; string…
Dov Miller
  • 1,958
  • 5
  • 34
  • 46