Home Tutorial Java Core Java Thread : toString() method

 
 

Share on Google+Share on Google+
Java Thread : toString() method
Posted on: October 18, 2012 at 12:00 AM
Advertisement
In this section we are going to describe toString() method with example in java thread.

Java Thread : toString() method

In this section we are going to describe toString() method with example in java thread.

toString() method :

If you want to display string representation of thread you can use thread.toString() method.toString() :

 public String toString() : It returns a string representation of the thread. It display info of thread as thread's name, priority and thread group.

Example :In this example we are using toString() method to display info of thread.

public class ThreadToString implements Runnable {

	Thread thread;

	public ThreadToString() {
		thread = new Thread(this);
		thread.start();
	}

	public void run() {
		System.out.println(thread.toString());
	}

	public static void main(String[] args) {
		new ThreadToString();
	}
}

Output :

Thread[Thread-0,5,main]
Advertisement

Related Tags for Java Thread : toString() method :


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 18, 2012

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com