为什么在Java中使用并行数组? [英] Why use parallel arrays in Java?
本文介绍了为什么在Java中使用并行数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Java中的并行数组是否有任何实际用例?维护相互关联的N个数组似乎太麻烦了。
Is there any real use case for parallel arrays in Java? It seems too cumbersome to maintain N arrays which are interrelated.
示例:
int ages[] = {0, 17, 2, 52, 25};
String names[] = {"None", "Mike", "Billy", "Tom", "Stan"};
int parent[] = {0, 3, 1, 0, 3};
我可以创建一个Person类并将对象存储在一个数组中。会贵一点,但是很容易使用吗?
I can just create a class Person and store objects in one single array. Will be little more expensive, but much easy to use right?
推荐答案
并行数组是Basic等语言的延续一)没有数组以外的数据结构。您应该按照建议定义对象。
Parallel arrays are a holdover from languages like Basic (the original one) that had no data structures other than arrays. You should define objects as you suggest, instead.
这篇关于为什么在Java中使用并行数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文