Why use parallel arrays in Java?

前端 未结 4 1865
耶瑟儿~
耶瑟儿~ 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:41

    Classes are nicer, but if the use case is narrow, e.g. one method body, it's wasteful to create one. If you have a Pair class, you could specialize it for the purpose without creating a new class.

提交回复
热议问题