How to save list items on disk instead of memory in Java

前端 未结 7 2012
眼角桃花
眼角桃花 2020-12-09 06:50

I\'m looking for a data structure same as ArrayList in Java that saves items on disk instead of memory. Does java have such a data structure? Thanks

I want to have a

相关标签:
7条回答
  • 2020-12-09 07:38

    Just to make the set of answers complete :)

    XStream

    XStream is a simple library to serialize objects to XML and back again.

    Person joe = new Person("Joe", "Walnes");
    joe.setPhone(new PhoneNumber(123, "1234-456"));
    joe.setFax(new PhoneNumber(123, "9999-999"));
    

    Now, to convert it to XML, all you have to do is make a simple call to XStream:

    String xml = xstream.toXML(joe);
    

    The resulting XML looks like this:

    <person>
      <firstname>Joe</firstname>
      <lastname>Walnes</lastname>
      <phone>
        <code>123</code>
        <number>1234-456</number>
      </phone>
      <fax>
        <code>123</code>
        <number>9999-999</number>
      </fax>
    </person>
    
    0 讨论(0)
提交回复
热议问题