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
2 answers

C# single character date format

I'm trying to get only the day, or the hour from a DateTime object. Though, I'm facing the problem that single-character dateformat strings are not accepted, because some of them have a special meaning. The following throws a…
Dries Geenen
  • 582
  • 5
  • 14
0
votes
1 answer

My code keeps on Printing " [Ljava.lang.String;@4e50df2e "not really sure where to and how to put this toString()

** as you can see I have made a program to print Student Record of same branch and college in which user inputs the name and roll number. I have tried generating toString() from my IDE but it is still showing " [Ljava.lang.String;@4e50df2e"…
AnsafGhani
  • 13
  • 4
0
votes
2 answers

How to generate GUI with multiple buttons and incrementing labels on them?

I am trying to generate a GUI using swing that creates a frame with 100 buttons and every button has a "label" on it from on 1 to a 100. What I have tried: import javax.swing.*; import java.awt.*; public class ButtonScreen extends JFrame{ …
qiu
  • 121
  • 7
0
votes
1 answer

Convert message object to string (Gmail api and python)

I am trying to save only a specific part of an email using python. I have the variables service, userId and msg_id but I don't know how to convert the variable plainText to a string in order to take the part that I want in the get_info function def…
alex999ar
  • 27
  • 6
0
votes
0 answers

How to convert variable type IntPtr to ToString in C#

I have a variable IntPtr with value, ex IntPtr I is 01x0712314. How I can show "01x0712314" of variable above to label, textbox or set value to variable string A in C# I had try with .ToString(), Int a = (int)I. all value after convert from…
0
votes
2 answers

error: incompatible types: String[] cannot be converted to String

I tried taking input of a 6 by 6 matrix in java using the string split function when the string is input in the following way, and to print the matrix. 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 The output that I get…
0
votes
1 answer

Why does toString() works even without any object or string to call upon

Noticed something in a codebase that I am working on. If you just execute toString() without any object to call upon it just works! Initially I thought this must be the result of implicit call on the window object but it wasn't as apparent from…
Vinay
  • 7,442
  • 6
  • 25
  • 48
0
votes
2 answers

Java how to use toString method to return an accessor method

I've been working on this for a while and can't seem to get my head around it. I'm trying to calculate the volume and surface area from the length, height, and width (without putting the volume or surface area in the data fields) using the accessor…
Francesca
  • 5
  • 3
0
votes
2 answers

Displaying a value in my View throws an error with ToString if value is null

In my view in asp.net core, I am trying to display my values in a @foreach. Here it is @foreach (var item in Model) { @item.FirstName @item.LastName @item.Birthdate.Value.ToString("d") …
0
votes
1 answer

the contents of arraylist are printed using println. I want a similar functionality for my created objects without using toString() function in java

In the image above, the contents of the arraylist is printed using println. I want a similar functionality for my created objects without using toString() function in java please tell me how can i do that
0
votes
1 answer

How to get the contents of a saved text file (Java)

Is there any way to get the contents of a text file as a string? For example, I have the contents of the file as: Name: John, Age: 34, Email: someone@example.com I have seen similar questions, but they don't get me anywhere. Edit: My code - …
Sid110307
  • 497
  • 2
  • 8
  • 22
0
votes
1 answer

Appending, using '+', a String vs a char

Whenever I tried to generated toString() method with IntelliJ IDEA, I see return ... + ", some='" + '\'' + // some is an String field '}'; Does it make any significant performance gain against following signature? return ... + …
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
0
votes
0 answers

Restore List from a String in Java

How do I restore List.toString back to List data type in Java for eg: List abc = new ArrayList(List.of("Why", "this", "Question")); String myStringValue = abc.toString(); System.out.println(myStringValue); Output [Why,…
0
votes
1 answer

File to String Null Pointer Exception

I'm trying to pass the contents of a file into a method as a String and encountering a Null pointer exception. I'm converting the file into a String like so: import java.io.*; public class FileHandler { String inputText = null; public…
0
votes
1 answer

Return all values of a dynamic stack linkedlist in a toString method

I'm trying to figure out how to output all the versions of the node "latest" using a toString method, but I'm confused as to how to make the while loop work correctly in this case. I was wondering if there is a method to go about doing so. Here's…
bruhHelp
  • 9
  • 5