Java Thread : toString() method


 

Java Thread : toString() method

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

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]

Ads