java.lang.Thread.toString()%uA0方法返回当前线程的字符串表示形式,包括线程名称,优先级和线程组。
声明
以下是java.lang.Thread.toString()方法的声明
public String toString()
参数
-
NA
返回值
此方法返回该线程的字符串表示形式。
异常
-
%uA0
例子
下面的例子显示java.lang.Thread.toString()方法的使用。
package com.yiibai 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() } }
让我们来编译和运行上面的程序,这将产生以下结果:
Thread[Thread-0,5,main]