当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Existing Complex data structures

问题描述:

is there a data structure like a set which can take different types as parameters? or do I have to create my own class?

an example to clarify...something like

DataStructure mydatastruct = new DataStructure ()

I'm I asking too much? :P

I meant something like this..I dont know why is not showing like I'm actually writing it

DataStructure <type1, type2, type3,...> mydatastruct = new DataStructure <String, Integer, String> ()

网友答案:

Yes, they are called Generics.

网友答案:

You probably mean the datastructure called tuple in other languages. They don't exist in Java.

In C++ you have the generic (aka. template) class called pair which implements your example above for 2 types, but this doesn't exist either in Java. However it is pretty easy to implement it yourself if you need such functionality often.

分享给朋友:
您可能感兴趣的文章:
随机阅读: