简体   繁体   中英

Comparing args value with string in java

I am trying out this code

catch (Exception e) {
 
String s="-help";
String s1="[-help]";
  if(s.equals(args) || s1.equals(args))
  {
    System.out.println("hello");
  }
  else 
  {
  log.info(e.getMessage());
  
  HelpFormatter formatter = new HelpFormatter();
  formatter.printHelp("AutoLockComponent ", options, true);
 
  }
  
  
}

But every single time while i am trying to debug the code it always going to else block instead of going into if condition,i mean the output that is am excepting is "hello" but i am getting log.info message printed, can anyone help me out in this, your help will be really appreciated, Also i am attaching the debugger info image for args value. 在此处输入图片说明

args is an array. Not a string. In the specific case you want args[0] .

if(s.equals(args[0]) || s1.equals(args[0]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM