0

I have an ArrayList that is not vary memory intensive, it stores only two fields,

 public class ExampleObject{

 private String string;
 private Integer integer;

 public ExampleObject(String stringInbound, Integer integerInbound){
 string = stringInbound;
 integer = integerInbound;
 }

I will fill an ArrayList with this objects

  ArrayList<ExampleObject> = new ArrayList<ExampleObject>();

for raw, hard core performance is it much better to use a hashset for this? If my ArrayList grows to a vary large number of items with an index in the the hundreds, will I notice a huge deference between the ArrayList of Objects and the hashset?

5
  • For raw hard core performance it is much better to run your code through a profiler. And brush up on performance characteristics of collections. Commented Jan 29, 2013 at 12:23
  • tell me more about profilers. any one that you can recommend to use? Commented Jan 29, 2013 at 12:25
  • 1
    It also depends on, how you access your Set/List. On random or in a loop ? Commented Jan 29, 2013 at 12:25
  • Google for "profiler android"? Commented Jan 29, 2013 at 12:28
  • Also, it's impossible to answer even in theory without knowing how the collection is being used. They have very different characteristics for write-heavy code, read-heavy code, when the collection size is small vs. big, whether it's modified heavily while it exists... Commented Jan 29, 2013 at 12:29

2 Answers 2

3

Although they are both Collection, I suggest that you read the differences between a Set and a List.

They are not used for the same purpose. So choose the one that meet your implementation requirements before thinking about performance.

Sign up to request clarification or add additional context in comments.

Comments

1

It all depends on what you're doing. How is data added? How is it accessed? How often is it removed?

For example, in some situations it might even be better to have parallel arrays of String[] and int[] -- you avoid collection class overhead and the boxing of int to Integer. Depending on exactly what you're doing, that might be really great or incredibly dumb.

Memory consumption can have a strong effect on performance as data sets get larger. A couple of IBM researchers did a neat presentation on Building Memory-efficient Java Applications a few years back that everyone who is concerned about performance should read.

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.