I am using Java to split a search query on it’s spaces
example:
String[] queryParams = queryString.split(" ");
so search for “New York Yankees” will get put into an array of three elements.
Now, I want to iterate over each of those elements (regardless of the length of the query) and store them in their respective variables so I can dynamically populate another part of my program.
Thanks
A simple for loop can iterate over your array.
Then if you want to use those values in another method of your program I’d suggest you pass your array to your method or just pass a single value (if you don’t need every values) by calling your method like that :
aMethod(queryParams[*anIndex*]);(in which case you wouldn’t need to iterate on your array and assign to variable.If you really want to assign your values to ids, maybe you could put them in a
mapin your for loop.