List Store Java objects

Source: Internet
Author: User

An array was returned before XML innuendo was read, which would not solve the problem of data import; The next step is to write a Java class (like the Hibernatepojo Class), instantiate the object list store when reading XML, and then return, storing the data as an object, easy to manipulate ....

In fact, it is very simple to write an object, List.add (object) to List on the line,

Read acquisition Time type conversion (class name) listobject.get (0);

A simple example of a student class (in the graduation project is equivalent to Pojo)

Publicclass XSB {

privateintxh;

Private String XM;

publicint getxh () {

return XH;

}

publicvoid setxh (int xh) {

this. xh = XH;

}

Public String Getxm () {

return to XM;

}

publicvoid Setxm (String xm) {

this. xm = XM;

}

}

Main class:

Publicclass Test {

Public List<object> GetList () {

list<object> list = new arraylist<object> ();

XSB xs=New xsb ();

XS.SETXH (1);

XS.SETXM ("John");

List.add (XS);

XSB xs1=New xsb ();

XS1.SETXH (2);

XS1.SETXM ("Dick");

List.add (XS1);

return list;

}

publicstaticvoid Main (String[]args) {

list<object> listObject = new arraylist<object> ();

Test te=New test ();

Listobject=te.getlist ();

XSB xs= (XSB) listobject.get (1); Read the objects in the list

System.out.print (XS.GETXM ());

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.