I want to know how to place a conditional breakpoint in Eclipse. I have a code like:
public static void doForAllTabs(String[] tablist){
for(int i = 0; i<tablist.length;i++){
--> doIt(tablist[i]);
}
}
Now I want to put a breakpoint on the line with the arrow but want it to trigger only if:
tablist[i].equalsIgnoreCase("LEADDELEGATES");
This question is related to
java
eclipse
debugging
conditional-breakpoint
1. Create a class
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s[] = {"app","amm","abb","akk","all"};
doForAllTabs(s);
}
public static void doForAllTabs(String[] tablist){
for(int i = 0; i<tablist.length;i++){
System.out.println(tablist[i]);
}
}
}
2. Right click on left side of System.out.println(tablist[i]); in Eclipse --> select Toggle Breakpoint
3. Right click on toggle point --> select Breakpoint properties
4. Check the Conditional Check Box --> write tablist[i].equalsIgnoreCase("amm") in text field --> Click on OK
5. Right click on class --> Debug As --> Java Application
From Eclipsepedia on how to set a conditional breakpoint:
First, set a breakpoint at a given location. Then, use the context menu on the breakpoint in the left editor margin or in the Breakpoints view in the Debug perspective, and select the breakpoint’s properties. In the dialog box, check Enable Condition, and enter an arbitrary Java condition, such as
list.size()==0
. Now, each time the breakpoint is reached, the expression is evaluated in the context of the breakpoint execution, and the breakpoint is either ignored or honored, depending on the outcome of the expression.Conditions can also be expressed in terms of other breakpoint attributes, such as hit count.
A way that might be more convenient: where you want a breakpoint, write a no-op if statement and set a breakpoint in its contents.
if(tablist[i].equalsIgnoreCase("LEADDELEGATES")) {
--> int noop = 0; //don't do anything
}
(the breakpoint is represented by the arrow)
This way, the breakpoint only triggers if your condition is true. This could potentially be easier without that many pop-ups.
Make a normal breakpoint on the doIt(tablist[i]);
line
Right-click -> Properties
Check 'Conditional'
Enter tablist[i].equalsIgnoreCase("LEADDELEGATES")
Source: Stackoverflow.com