0

I have 7 textfields in my jsp which are presently being filled from a List of parameters which i get from server.

By using a List I iterate parameters, which I feel gets order-dependent. Eg I have to traverse from index 0-6. So let's say later I change the order of parameters my logic will have to change and change code everytime.

I thought of keeping parameters in a Map and then I will get like Map.get("xyz").

Is there a better solution to it??

Siddharth Trikha
  • 2,648
  • 8
  • 57
  • 101

3 Answers3

0

If I understand you well, you want to have a random-access to any element in your data structure. Your can use arrayList for it. It also would allow you to change order of your elements quite easily anytime.

http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

A map is used to have some elements indexed by some other elements. If you intend to have some values mapped to your parameters, that may work indeed. Still when changing your implementation you'll always have to watch for fragile points.

3yakuya
  • 2,622
  • 4
  • 25
  • 40
0

I think your Map approach is actually a good solution to the issue.

Julio
  • 401
  • 4
  • 14
0

If orders are not an issue then better to go with Map: When to use HashMap over LinkedList or ArrayList and vice-versa Try this link:

Community
  • 1
  • 1
Aroon
  • 167
  • 1
  • 8