I have a List called dbData and two StringBuilders called infoSB and historySB. I’ve debugged my project and the two StringBuilders have all the data they are supposed to have, but for some reason it also adds some random characters to the data. All I’ve done to add the data is the code below:
dbData.add(infoSB.toString());
dbData.add(historySB.toString());
The characters being added are [ ] and ,
Has anyone ran into this before and know how to keep it from doing this?
UPDATE: Here is how I’m getting the data and assigning it to the StringBuilder.
JSONObject json_data = jArray.getJSONObject(i);
double altitudeData = json_data.getDouble("altitude");
double altitudeInFeet = altitudeData * 3.281;
historySB.append("Altitude: " + df.format(altitudeInFeet) + "ft\n");
Are these characters at the beginning and end of the string, and is the a comma somewhere in the middle? This is what the
toStringmethod ofListis meant to do.If you have a list of three elements
Then the list will create the following string
[car, van, bike]. The[]denote the beginning and end of the list, and commas denote the boundary between elements.If you just want to concatenate strings then either use the
+operator or aStringBuilder/StringBuffer.eg.