Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7494813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:47:19+00:00 2026-05-29T17:47:19+00:00

In my project i need to load aml data from internet and after that

  • 0

In my project i need to load aml data from internet and after that parse it. I have no problem in parsing xml. Each xml has 20 elements. let me explain my question with a sample.

this is the format of xml:

<XML>
    <Item1> 
        <element1>a</element1> 
        <element2>b</element2> 
        ... 
        <element20>f</element20> 
    </Item1>
    <Item2> 
        <element1>d</element1> 
        <element2>s</element2> 
        ... 
        <element20>l</element20> 
    </Item2>
...
</XML>

My question is about the class that i want to create. One way is creating class and put each element as its properties such as:

class myItems {
    private String element1;
    private String element2;
    ...
    private String element20;
    //and also adding all setters and getters
}

Therefore, each item of XML will have one object of this class. So, if i have 100 items in xml file, i will have 100 objects of this class.

second way is using ArrayList in the class. something like:

Class myItems {
    ArrayList<String> element1 = new ArrayList<String>();
    ArrayList<String> element2 = new ArrayList<String>();
    ...
    ArrayList<String> element20 = new ArrayList<String>();

    //and for setters and getters
    public ArrayList<String> getElement1() {
        return element1;
    }
    public void setElement1(String str) {
        this.element1.add(str);
    }
    ...
}

Therefore, I have one object that it has all of my variables.

My question is, which of these ways is better in terms of speed, memory consumption and anything else?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T17:47:20+00:00Added an answer on May 29, 2026 at 5:47 pm

    The best way to do this in my opinion is have a clear model of the object you’re trying to represent, as a class:

    class Item {
        private member; // etc.
        ...
    }
    

    You will want to abstract meaningless stuff from the XML structure into your class. For example, you could combine two or three elements from the XML into one member if it makes sense. You can do that when creating the object. You will end up with a smaller footprint (fewer public methods) and a clearer implementation. Then, you can represent the list of items in your program as a List:

    List<Item> allItems = new ArrayList<Item>()
    

    Personally, I believe that if you’re not facing serious performance constraints from the beginning (which I don’t think you are), clarity and clean implementation trumps performance. You should be more careful about design as opposed to performance right now. Premature optimization is generally viewed as a bad thing.

    Unrelated, here is an interesting presentation on Java memory consumption :).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Junits I have in my project need to load property files from the
I have few 'so' files that I need to load in maven java project
I have many, (15-20) different XML files that I need to load to VB.Net.
For a new project I need to load big XML files (200MB+) to a
We have a project that will need to work in IE6,7,8. I'm not that
I have about 20-ish high quality images (~3840x5800 px) that I need to load
I have taken Problem #12 from Project Euler as a programming exercise and to
I have this project that I need a modal box to appear when they
to my project i need document editor for many types of documents(tabular data, invoices,
In my project I need to create a business object validation layer that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.