It is not recommended to use the ArrayList method of storing keys in even numbers and storing values in odd numbers. This goes against the general logic of how we write code and will also cause great trouble to future maintainers. Moreover, the performance of mobile phones nowadays is very good. In your usage scenario, there is no need to consider performance issues.
For the case where the amount of data you mentioned is less than 10, the error between ArrayList<String> and HashMap<String, String> is very small, and using either one will not affect the performance; but discussing this issue from a technical level, I will just say a few words. ^.^
ArrayList is an ordered collection, and its bottom layer is actually an array. If it is traversed and stored, it is still faster than HashMap, but its addition and deletion will be slower, especially adding and deleting from the middle of the list (distant)
HashMap is an unordered hash table, and its query order is directly related to the amount of data. To put it simply, the larger the amount of data, the slower the query!
Summary: Small Data: Both can be used. Big data: ArrayList is frequently used for queries, and HashMap is used for frequent additions, deletions, and changes. Very large data: use ArrayList;
Although I don’t know why you want to compare the storage of List<String> and Map<String, String> which one is faster? There are different implementation classes for these two interfaces, such as ArrayList and LinkedList, which are very different, and HashMap, TreeMap, LinkedHashMap, WeakHashMap, and IdentityHashMap have very different implementation class behaviors, efficiency, object storage cycles, and key equivalence strategies. Just pretend I didn’t answer/(ㄒoㄒ)/~~
The performance has been explained very clearly upstairs. If the stored data is less than 10, you can directly specify the maximum value of 10 when declaring, which can save memory space.
List<String> list = new ArrayList<>(10);
Map<String, String> map = new HashMap<>(10);
It is not recommended to use the ArrayList method of storing keys in even numbers and storing values in odd numbers. This goes against the general logic of how we write code and will also cause great trouble to future maintainers. Moreover, the performance of mobile phones nowadays is very good. In your usage scenario, there is no need to consider performance issues.
For the case where the amount of data you mentioned is less than 10, the error between ArrayList<String> and HashMap<String, String> is very small, and using either one will not affect the performance; but discussing this issue from a technical level, I will just say a few words. ^.^
ArrayList is an ordered collection, and its bottom layer is actually an array. If it is traversed and stored, it is still faster than HashMap, but its addition and deletion will be slower, especially adding and deleting from the middle of the list (distant)
HashMap is an unordered hash table, and its query order is directly related to the amount of data. To put it simply, the larger the amount of data, the slower the query!
Summary:
Small Data: Both can be used.
Big data: ArrayList is frequently used for queries, and HashMap is used for frequent additions, deletions, and changes.
Very large data: use ArrayList;
This is related to the amount of data
It depends on how you use it. If you just store and traverse List, it is faster. If you want to check the value by key, Map is faster
Although I don’t know why you want to compare the storage of List<String> and Map<String, String> which one is faster? There are different implementation classes for these two interfaces, such as ArrayList and LinkedList, which are very different, and HashMap, TreeMap, LinkedHashMap, WeakHashMap, and IdentityHashMap have very different implementation class behaviors, efficiency, object storage cycles, and key equivalence strategies. Just pretend I didn’t answer/(ㄒoㄒ)/~~
The performance has been explained very clearly upstairs.
If the stored data is less than 10, you can directly specify the maximum value of 10 when declaring, which can save memory space.