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
1 answer

Problems with toString() and Overriding Methods

I am having a problem with this code. It is not calculating area correctly. I need it to calculate the cross-sectional area of a Cylinder/Piston and the surface area of the cylinder. If you notice the output it seems that both values are the same…
DIowa
  • 9
  • 1
0
votes
2 answers

Using the Adress class in Student class with toString in java

I'm trying to create a program where you can add Student info with their address. Therefor I have created 2 classes, class Student and class Adres (dutch for address). In the Adres class I have the address data and in Student the student data. But…
Ronny Giezen
  • 557
  • 2
  • 10
  • 21
0
votes
1 answer

bracket expected with toString

Helli, I got an error message ") expected" with my code this is my code @Override protected void onActivityResult(int requestCode, int resultCode, Intent data){ super.onActivityResult(requestCode, resultCode, data); …
0
votes
0 answers

Custom annotation for customized toString method, which return first 10 elements from ArrayList

I'm trying to make a custom annotation at class level, to genrate a ToString() method which returns all the field value in a string as they are, but if any field is of type List then we want only first 10 elements from List not whole list (as in…
0
votes
1 answer

Why does ToString format a number with the incorrect decimal separator

In my locale settings->numbers/currency, the decimal symbol is set to a period. Yet when I use the following in a Razor view: @Model.TendersReceived[i].Wq.ToString("N") It renders the number with a comma as a decimal…
ProfK
  • 49,207
  • 121
  • 399
  • 775
0
votes
1 answer

How to use ToString in Stacks

I am having trouble writing a ToSting method to show the size in the array get rid of the brackets in the Stacks expected: RED= GREEN= BLUE= SIZESINSTOCK=S:0 M:0 L:0 XL:0 BIG:0 SOLDOUT=S:0 M:0 L:0 XL:0 BIG:0 But…
Tad Ye
  • 1
  • 1
0
votes
2 answers

Java how to print "x" number of stars inside brackects

I need to print players and star they get, answer should be: Create player... Name: Player3 Stars: 4 Print: Player3(***) Now I get this: Create player... Name: Player5 Stars: 4 ()()()() Print: Player5(*) (Above stars inside brackects) here is my…
lehtojy1
  • 51
  • 7
0
votes
2 answers

Creating a toString from an array

I am trying to create a toString to print the detail of my array. I can have it print how I want it to look by doing a for loop and using print line with in the toString but obviously dosn't really work when I want to use it in the main part of my…
Nico
  • 17
  • 3
0
votes
1 answer

Limiting the length of a toString return

I need to make a program that returns an error list in a file. The problem I'm having is that it returns the String in one big line, with the following toString method: @Override public String toString() { return "Resultat{" + …
MaelPJ
  • 11
  • 1
0
votes
1 answer

toString() method not being executed when using JSTL

I have an ArrayList with some class objects which take on variables in the constructor and with getters, setters and a toString() method. So I want to loop through that ArrayList with the tag provided by JSTL. The toString() method…
syclone
  • 99
  • 13
0
votes
1 answer

using toString to form a String with Characters

using the toString method to add characters into my string I form the word "LAUGHTER". However, the program does not recognize the word = "LAUGHTER" and therefore it did not enter my if loop. Any idea why is it like that? word +=…
Zac Ee
  • 31
  • 5
0
votes
2 answers

Java toString() How to return String message in place of null

How can I print an "error" String message in a field that returns null? Here's what I'm trying to do: When passed an animal object, the toString() method should return a string that looks like this. Name: "fluffy" Breed: Pitbull Age: Data not…
Abby Howe
  • 86
  • 1
  • 12
0
votes
1 answer

In Anylogic how do you extract the name of an object so i can use and assign it as a Text value? (Object >> Text)

The Problem: An agent has a parameter that refers to an object (lets say an INode). I want to get and use the name of that INode as plain text without writing a function that maps INodes to their names. If currentLocation (which has a value of…
Wilmark
  • 39
  • 5
0
votes
2 answers

How to convert to two decimal places

How I can get the value that the user inputs to round to two decimal places. I tried to use.ToString("N2") but it gave me an error of {cannot convert string to System.IFormatProvider}. I can't seem to find a solution to this error. code is here:…
Danny
  • 11
  • 5
0
votes
2 answers

return array with toString()

I have an array and I would like to return it in the end but I dont know how to return it with the name and the []. All I get now is s[[LCat;@3b250bf7] This is my arrray and a class of cats. I start at 0 because I only want to make the array bigger…
1 2 3
99
100