I am attempting to build a string using a for()
loop to iterate over the elements of an ArrayList
. I want to append a coma after each element of the ArrayList is appended on to the String that I'm building, but I don't want to append the coma after the last element of the ArrayList has been appended.
This is what I've attempted so far, but a coma is still added in after the last element.
public String buildWOEIDQuery(ArrayList searchCriteria)
{
String query = "http://where.yahooapis.com/v1/places.q('";
for (int i = 0; i < searchCriteria.Count; i++ )
{
if(searchCriteria.)
query += (String)searchCriteria[0];
if(i != searchCriteria.Count)
{
query += ",";
}
}
query += "')?appid=" + devKey;
return query;
}
The query should end up looking like this if, for example there are 3 search criteria:
http://where.yahooapis.com/v1/places.q('criteria1,criteria2,criteria3')?appid=dj0yJmk9Tm
If i
is equal to the Count of the ArrayList, doesn't that make it the last element of the list, thus should no append a coma?