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

Write data to textbox automatic

I am trying automatic write data to textbox9. I am using timer, but I don't find why it's not working. Maybe somebody have suggest for me. System.Timers.Timer aTimer; public int i; private void Form1_Load(object sender, EventArgs e) { i = 0; …
0
votes
2 answers

Why is it common practice to override the method toString() in java to print the instance variables of the class?

As I've been learning and even some IDEs have it embeded in it, to override the toString() method to print out all instance variables of the class. The original toString() defined in object.java is defined as follows: public String toString() { …
user12184817
0
votes
1 answer

Why does it return entire array in java

Hi so im writing a program and i want to return part of an array that does doesnt include null or 0 in it. so the array is originally int and i converted it to string and use this public String toString(){ // TODO: Return the String with the…
0
votes
2 answers

How to make a Task and Todo Program in Java?

I want to make a Task and Todo program. I have written the code in separated classes. The class Task will represent a single item that needs to get done. public class Task { private String task; private int priority; private int workload; public…
0
votes
2 answers

How to avoid `std::to_string()` making a very small double number to 0?

I have a requirement to store very small double numbers into a string format and then later reverse them. However, when I try to run std::to_string() on a small number like 4.7816457028269855e-143 then it simply makes it 0. I referred Set precision…
iammilind
  • 68,093
  • 33
  • 169
  • 336
0
votes
1 answer

JNI - How to get the Double.toString() method to convert a jdouble to a jstring

So I want to be able to convert a jdouble to a jstring using the inbuilt Double.toString() from c++. This is how I think I would do it. jdouble result; //Get the class for Double so we can get the method id of toString(). jclass doubleObjectClass =…
Nitrogen
  • 89
  • 6
0
votes
1 answer

Significant Figures in Numerical Values

I am trying to make a calculator of sorts where you perform an operation and the code returns an answer that follows the rules of significant figures. Here is a boiled down portion of what I have coded: var x = 0.002.toString().split(""); //to…
0
votes
4 answers

How to avoid last comma when implementing a collecion ToString

I'm implementing a customize toJson() method. One of my class member is a dictionary. I did : sb.Append("\"DateSource\" : {"); foreach (var row in DateSource) { sb.Append("["); …
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
0
votes
2 answers

Unable to print out b.toString and c.toString

The program's purpose was to teach me how to create a character list, and practice using toString and booleanequals(object other). public class CharList { private char[] Array = new char[100]; private int numElements = 0; public…
0
votes
3 answers

How to add spaces to every two numbers with JavaScript?

I like to output a formatted number with a space after every two numbers, I've tried this: function twoSpaceNumber(num) { return num.toString().replace(/\B(? 1 23 45 67 89 (…
0
votes
0 answers

Confusion with Java inner private classes and toString()

I have a project where I must use inner classes to declare types of food (created as 'Item' objects); for example, Pancake: private class Pancake { Item pan = new Item(5.50); public String toString() { …
0
votes
1 answer

Incorrect outputs for toString method for List implementation

I am implementing a generic List class and not getting the expected output. My current output is: [0, 1, null] Expected Output in a separate test class: List list = new SparseList<>(); list.add("0"); list.add("1"); list.add(4, "4"); will result in…
Keeley
  • 95
  • 6
0
votes
2 answers

How should I go about printing all elements in an ArrayList via a toString in a formatted manner?

What I am asking is that, in Java 8, when I call my toString() method (overridden), I am trying to print out the elements of each respective ArrayList in this manner: - str1 - str2 - str3 But instead, when I return the ArrayList, it…
rjoor
  • 3
  • 5
0
votes
1 answer

How do you convert a data frame column to a string?

What I am trying to do is take a column of a dataframe and convert it to a delimited string to be used as part of an input for a graphViz Function. I have the following code: library(DiagrammeR) vector <- ('A->1', 'B->2', 'B->3',…
SQALEX101
  • 209
  • 1
  • 3
  • 16
0
votes
1 answer

how to convert object into string?

I have this problem converting object into string... I make use of the toString() function... and since the conversion of object into string were inside the try{}catch(exception e){}, i keep on receiving an output error: For input string: "" What…
iamanapprentice
  • 411
  • 5
  • 19
  • 37