-1

filterConditions is {ID>=3,amount<400}

 String[] fCondition = filterConditions.split(",");
        if(fCondition[i].contains(">=")){
            int indx1= fCondition[i].indexOf("=");
            int indx2= fCondition[i].indexOf("=");
            String f1 = fCondition[i].substring(0, indx1);
            String f2 = fCondition[i].substring(indx2);
            fieldList.add(Filters.gte(f1, Integer.valueOf(f2)));
            continue;
        }
svm
  • 25
  • 1
  • 9
  • Show the filtercondition value and sample document. – notionquest Mar 27 '17 at 18:02
  • filterConditions value is "ID>=3,amount>300" @notionquest – svm Mar 27 '17 at 18:12
  • When you are getting the substring value for f2, please use indx2 + 1. This should get you only 3 without the equalto. – notionquest Mar 27 '17 at 18:30
  • 1
    Possible duplicate of [What is a NumberFormatException and how can I fix it?](http://stackoverflow.com/questions/39849984/what-is-a-numberformatexception-and-how-can-i-fix-it) – xenteros Apr 10 '17 at 09:35

1 Answers1

0

Change the f2 assignment to indx2+1 to get the value 3. Currently, the substring gets the value from "=3".

String f2 = fCondition[i].substring(indx2+1);

Index of:-

Count starts from 1.

Returns the index within this string of the first occurrence of the specified character. If a character with value ch occurs in the character sequence represented by this String object, then the index (in Unicode code units) of the first such occurrence is returned.

The below indexOf returns 4.

int indx2= fCondition[i].indexOf("=");

Substring starts from 0. When you get 4 for the substring, it gets the value from =. So, it has to be changed to index+1.

int indx2= fCondition[i].indexOf("=");
notionquest
  • 37,595
  • 6
  • 111
  • 105