Java Data Type Tutorial - Java Thread.toString()








Syntax

Thread.toString() has the following syntax.

public String toString()

Example

In the following code shows how to use Thread.toString() method.

/*  ww w .ja  va  2s. c  om*/
class ThreadDemo implements Runnable {
  Thread t;
  ThreadDemo() {
    t = new Thread(this);
  
    t.start();
  }

  public void run() {

    System.out.println(t.toString());
  }

}

public class Main {

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

}

The code above generates the following result.