Android Question What is the best way to return an structure of values from a class?

davepamn

Active Member
Licensed User
Longtime User
Should I use a type of return a list of values from a class or should I use a map?
 

Roycefer

Well-Known Member
Licensed User
Longtime User
It depends on the details and needs of your program. If you plan on iterating through the results, a List will be better. You can iterate through the values of a Map but they won't necessarily be in the same order in which you put them in the Map. If you want to be able to access the values using a key/value pattern where key is not just an integer, then obviously a Map will be better.

You can also create a custom Type whose fields contain all your info and return an instance of that Type.
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
The type worked.

I put the type in the class. However, it seems like that is a strange place to put the type because it is difficult to find logically
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
Usually "data types" are kept in a header file or a specification module. I want to organize the "type" structure in a best practice manner.
 
Upvote 0

SteveTerrell

Active Member
Licensed User
Longtime User
Usually "data types" are kept in a header file or a specification module. I want to organize the "type" structure in a best practice manner.

A C type #include "header file path and name" would be helpful where the same types or constants are used in several projects. This way only one file needs to be maintained.
 
Upvote 0

MaFu

Well-Known Member
Licensed User
Longtime User
A C type #include "header file path and name" would be helpful where the same types or constants are used in several projects. This way only one file needs to be maintained.
Put it in a code module Process_Globals and save this file in your "Shared Modules" folder. Then you have only one file using everywhere.
 
Upvote 0
Top