Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 11:01

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



toString method - cant understand this example

Discussion on toString method - cant understand this example within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,234
Received Thanks: 1,095
toString method - cant understand this example

Code:
class PointCoordinates {

	private int x, y;
	public PointCoordinates(int x, int y) {
		this.x = x;
		this.y = y;
	}
	public int getX() {
		return x;
	}
	public int getY() {
		return y;
	}
}

public class ToStringDemo {

	public static void main(String args[]) {
		PointCoordinates point = new PointCoordinates(10, 10);
		// using the Default Object.toString() Method
		System.out.println("Object toString() method : " + point);
		// implicitly call toString() on object as part of string concatenation
		String s = point + " testing";
		System.out.println(s);
	}
}
i have this example from google. but i implemented it to my own script yet i still dont understand how it works and whats it for and what EXACTLY it does.
fear-x is offline  
Old 07/02/2014, 17:12   #2
 
tolio's Avatar
 
elite*gold: 2932
The Black Market: 169/1/0
Join Date: Oct 2009
Posts: 6,966
Received Thanks: 1,097
you should read the full page and test it to see the difference
tolio is offline  
Thanks
1 User
Old 07/02/2014, 17:20   #3
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,234
Received Thanks: 1,095
i read it all but too complicated... and to me java seems too much complicated overall
fear-x is offline  
Old 07/02/2014, 19:35   #4
 
strubelz's Avatar
 
elite*gold: 31
Join Date: Jan 2014
Posts: 310
Received Thanks: 55
The Method you wrote is an example of the default toString Method, if you want to implement a custom one, just read the complete site. Basicly what you need to do is just creating a class that extends the class for that you want to create a custom toString Method and Override the toString Method. Your Method needs to return a String, this String should contain all Information of the class in you own format.
strubelz is offline  
Thanks
1 User
Old 07/03/2014, 20:05   #5
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,234
Received Thanks: 1,095
whats the point of this toString though? if you can simply just return all the data one by one and see the values?
fear-x is offline  
Old 07/04/2014, 01:04   #6
 
elite*gold: 0
Join Date: May 2012
Posts: 23
Received Thanks: 1
Whats the point of C when u can "simply" do it in Assembler

For instance if u want to print a lot of player stats more than one time to the screen u can do it with "player.toString()" rather than "Stamina: " + player.stamina + "\nAgility: " + player.agility and so on.

It just gives u the possibility to represent an object as a string.
But u don't have to use it :P

Please correct me if I'm wrong!
-Epitaph- is offline  
Thanks
1 User
Old 07/04/2014, 01:41   #7
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,234
Received Thanks: 1,095
now THAT ! cleared out well for me ! i get the point of it now

instead of printing 20 lines... prints one line and everything is returned :P cool ! like a debug-ish
fear-x is offline  
Old 07/04/2014, 13:12   #8


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
toString is used for debug purposes mostly.
A nice debugger will show you the string representations of objects instead of some complex object tree. Hence you can easily see crucial information about your objects while stepping through your code.
MrSm!th is offline  
Thanks
1 User
Old 07/04/2014, 13:28   #9
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,234
Received Thanks: 1,095
thank you all guys ! thank you very much
fear-x is offline  
Reply


Similar Threads Similar Threads
Binary (toString) Problem
04/15/2012 - AutoIt - 4 Replies
Hallöchen, meine Situation ist folgende: Ich habe ein Script mit einem Binarycode: $rezBinary = '0x262352657A4D67722056...' $rezBinary &= '0100000000000...' Ich habe einen RGB Farbcode den ich so in die einzelnen Farben auflöse: $color1 = StringTrimLeft($color1, 2) $color2 = StringTrimLeft($color2, 2) $red1 = StringTrimRight($color1, 4)
[TUT] anthrax28 bypass method(working method)edited by:akomsimojm [TUT]
04/09/2010 - Soldier Front Hacks, Bots, Cheats & Exploits - 36 Replies
SUCROSE anthrax28 bypass method(working method)edited by:akomsimojm *closed made another thread that is surely working



All times are GMT +1. The time now is 11:01.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.