1

I build an android application, and i stored around 5 array lists in static variables, so is this way recommended, and if its not, what is the affect of using such way on the performance of the application?

2
  • It all depends on the context. Commented Mar 17, 2014 at 9:50
  • static variables are belongs to class, not to any instances. Keep this in mind Commented Mar 17, 2014 at 9:51

1 Answer 1

1

It all depends on the context. Let's say you have a Library class that contains a List<Book>. You would want the List to be an instance variable since each library should have its own books. If you made the List<Book> static each instance of library would share the same List, which would be incorrect since libraries can have different books.

But let's say you had a class FootballTeam which contains a List<Position>. Since each Football team has the same positions this class could be shared amongst all instances of FootballTeam since one team's positions will not differ from anothers.

So it really depends on what is being placed within the List. Are the values stored in the List specific to a particular instance of a class? If so, they should not be static. Are the values common across of instances of a particular type? If so they could be static.

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

1 Comment

Thanks Kevin for your response I will illustrate more what is my question i have 5 lists returns from webservice and i need these lists with me along all activities in the application, so is it correct to make these lists static ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.