Why use parallel arrays in Java?

前端 未结 4 1867
耶瑟儿~
耶瑟儿~ 2021-01-12 23:57

Is there any real use case for parallel arrays in Java? It seems too cumbersome to maintain N arrays which are interrelated.

Example:

int  ages[]   =         


        
4条回答
  •  时光说笑
    2021-01-13 00:35

    Create Class/Object representation only if what you are trying to represent can be better explained as an object.

    Hash Maps are another solution. For example, instead of differnt arrays for ages and names, if the names are unique, you can use the name as keys and age as the value.

提交回复
热议问题