我想使用该程序检查区域,但是出了点问题我无法解决。

例如:abc,def,ghi,jkl,mno


  jkl = true;
  abc =炸弹


public boolean isDistrict (String districtCheck){

    StringTokenizer st = new StringTokenizer(address,",");
    int tokenno = st.countTokens();

    for(int i=0;i<tokenno-2;i++)
        st.nextToken();

    String district  = st.nextToken();
    if(st.nextToken()==district);
        return true
        else
        return flase

最佳答案

字符串不能与“ ==”进行比较,而应使用“ equals()”

您的代码必须是:

public boolean isDistrict (String districtCheck){

    StringTokenizer st = new StringTokenizer(address,",");
    int tokenno = st.countTokens();

    for(int i=0;i<tokenno-2;i++)
        st.nextToken();

    String district  = st.nextToken();
    if(st.nextToken().equals(district))
        { return true; }
        else {
        return false; } }

07-24 18:29