0

I have an ArrayList, and each object consists of an array of two floats representing coordinates. I found that I could serialize the ArrayList by calling the .toString() method on it, but this did not serialize the float arrays within the ArrayList. How can I go about serializing those as well?

Here is basically what I did:

private ArrayList<float[]> pointsList = new ArrayList<float[]>();

In an onTouch method, I add coordinates to the list:

float[] thisPosition = new float[2];
thisPosition[0] = touchX;
thisPosition[1] = touchY;
pointsList.add(thisPosition);

Then I serialize the ArrayList like this:

pointsList.toString();

But each item in the list is turned into F@426d51d8 and other strings like that. How can I serialize these sub-arrays and preserve their numeric values? I have searched forums here on StackOverflow and elsewhere, but other similar questions address how to make an ArrayList of String arrays or other ArrayLists.

3
  • You may want to use json for this stuff. Commented Feb 21, 2014 at 6:50
  • @arjun.9990 forgive me for being extremely new to java, but I thought that serializing was the process of converting my arrays to a json string. At least that's what it is in PHP and javascript. What would you actually recommend? Commented Feb 21, 2014 at 12:34
  • json is better if u want to transfer data across systems over internet.with android is being used for creating front end for many websites it is getting popular. android supports it you may like to read : developer.android.com/reference/org/json/package-summary.html Commented Feb 21, 2014 at 13:50

2 Answers 2

1

try this

Arrays.deepToString(pointsList.toArray());
Sign up to request clarification or add additional context in comments.

Comments

0

ArrayList's toString() method is calling toString() methods of list elements. float[] does not have self toString() method, so toString() method from Object class is used. This is why something like F@426d51d8 is printed.

To serialize array to string you should use Arrays.toString(a) method.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.