-3

Okay so here's my constructor

public class Highscore implements java.io.Serializable{

    public String name;
    public double score;
    protected Highscore (String na, double sc){
        name = na;
        score = sc;
    }
    public String getName(){
        return name;
    }
    public double getScore(){
        return score;
    }
    public String toString(){
        return name + "has "+score+" points.";

    }
}

Creating the object in my main class:

               Highscore ny = new Highscore (na, sc);
                allaHighscore.add(ny);

Then i want to save this object to be able to load them at a later point, this is for a highscore list for a game btw

How do I proceed?

Danubian Sailor
  • 1
  • 38
  • 145
  • 223
  • 1
    Sorry but you really could answer this yourself by reading the official [tutorial](http://xstream.codehaus.org/tutorial.html). – Kai May 30 '13 at 11:59

1 Answers1

2

XStream is extremally trivial to use. You just create the serializer:

XStream xstream = new XStream();

With single call you can convert any object to string

String xml = xstream.toXML(myObject);

and do what you want with that String, eg. save to file.

Deserialization is also trivial

MyBean bean = (MyBean)xstream.fromXML(xml);

Works with POJO's, Java collections, etc.

Danubian Sailor
  • 1
  • 38
  • 145
  • 223