Java.lang.StackTraceElement.equals() Method

Advertisements


Description

The java.lang.StackTraceElement.equals() method returns true if the specified object is another StackTraceElement instance representing the same execution point as this instance.

Declaration

Following is the declaration for java.lang.StackTraceElement.equals() method

public boolean equals(Object obj)

Parameters

  • obj -- This is the object to be compared with this stack trace element.

Return Value

This method returns true if the specified object is another StackTraceElement instance representing the same execution point as this instance.

Exception

  • NA

Example

The following example shows the usage of java.lang.StackTraceElement.equals() method.

package com.tutorialspoint;

import java.lang.*;

public class StackTraceElementDemo {

   public static void main(String[] args) {

      function1();
   }
 
   public static void function1()
   {
      new StackTraceElementDemo().function2();
   }
 
   public void function2() 
   {
      int i;  
    
      // ob is the object to be compared with this stack trace element
      Object ob = "a";
      System.out.println(Thread.currentThread().getStackTrace()[0].
      equals(ob));
   }
}  

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

false



Advertisements
Advertisements