Java检测String中的双引号

JAB*_*JAB 2 java string logic

示例代码

public static void main(String args[]){  
String test=null;   
if(some condition)  
   test = "\"abc\"";
else
   test ="def";

// if condition is true , in debug mode when i check the value of test its ""abc"" (double double quote);   
// if condition is false , then value of test is "def" (double quotes only one time);


}
Run Code Online (Sandbox Code Playgroud)

寻找一个逻辑来检查字符串是否有双引号.尝试下面的东西

// test.startsWith("\"\""))  // this didn;t work
Run Code Online (Sandbox Code Playgroud)

Yog*_*ngh 21

您正在检查2,"(double quotes)s而您的字符串在开头只有一个.试试以下:

 test.startsWith("\"");
 test.endsWith("\"");
Run Code Online (Sandbox Code Playgroud)

应该管用.