Well, thatโs what I came up with. We did not compile or test it, so there are no guarantees here
ArrayList<String> getQueryParamNames(String input) { ArrayList<String> result = new ArrayList<String>(); //If its everything after the ? then up to the first = is the first parameter int start = 0; int end = input.indexOf("="); if (end == -1) return null; //No parameters in string while (end != -1) { result.Add(input.substring(start, end)); //May need to do end - 1 to remove the = //Look for next parameter, again may need to add 1 to this result to get rid of the & start = input.indexOf("&", end); if (start == -1) //No more parameters break; //If you want to grab the values you can do so here by doing //input.substring(end, start); end = input.indexOf("=", start); } return result; }
I wrote this late at night without testing it, so you will have to adjust some calls by adding or subtracting 1. Also, I may have forgotten the exact syntax for adding to the List . I think commenting on any mistakes for others to see, but this is a common sense. I have a feeling that I forgot somewhere ; .
EDIT: set the result to a new ArrayList instead of LinkList as suggested below
source share