Java.lang.Thread.toString() Method

Advertisements


Description

The java.lang.Thread.toString() method returns a string representation of this thread, including the thread's name, priority, and thread group.

Declaration

Following is the declaration for java.lang.Thread.toString() method

public String toString()

Parameters

  • NA

Return Value

This method returns string representation of this thread.

Exception

Example

The following example shows the usage of java.lang.Thread.toString() method.

package com.tutorialspoint;

import java.lang.*;

public class ThreadDemo implements Runnable {

   Thread t;

   ThreadDemo() {

      t = new Thread(this);
      // this will call run() function
      t.start();
   }

   public void run() {

      // returns a string representation of this thread 
      System.out.println(t.toString());
   }

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

Let us compile and run the above program, this will produce the following result:

Thread[Thread-0,5,main]



Advertisements
Advertisements