Share on Google+Share on Google+

Java Thread : toString() method

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]

Advertisements

Posted on: October 18, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.