Home Tutorial Java Core Java Thread : toString() method

 
 

Java Thread : toString() method
Posted on: October 18, 2012 at 12:00 AM
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]

Related Tags for Java Thread : toString() method :


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.