[英]C++ to java, language equivalency questions
I've grown quite fond of some structures in C++, and I've recently been porting over some old school projects to java, but have run into a few snags that weren't resolved by simple google searches... So I figured that I'd ask here: 我已经非常喜欢C ++中的某些结构,并且最近我已经将一些老派项目移植到Java,但是遇到了一些障碍,这些障碍无法通过简单的Google搜索来解决...所以我想到了我在这里问:
In C++ I'm quite fond of Stringstream
, vector
, list
, and dequeue
, but haven't been able to find adequate documentation on any of them. 在C ++中,我非常喜欢Stringstream
, vector
, list
和dequeue
,但是还没有找到足够的文档。 When I try to use Vector
, netbeans tells me that it's deprecated, does that mean some other code took it's place? 当我尝试使用Vector
,netbeans告诉我它已被弃用,这是否意味着其他代码取代了它? Is there some other container I should be using instead? 还有其他我应该使用的容器吗?
Thanks! 谢谢!
For Stringstream
you can use java.io.ByteArrayOutputStream
对于Stringstream
,可以使用java.io.ByteArrayOutputStream
C++'s Vector<T>
is basically the same as java.util.ArrayList<T>
C ++的Vector<T>
与java.util.ArrayList<T>
基本上相同
The closest match for list<T>
would be java.util.LinkedList<T>
-- both are implemented as doubly linked lists (though if all you want is an ordered collection of elements you should probably use the more generic interface, java.lang.List<T>
) 与list<T>
最接近的匹配项是java.util.LinkedList<T>
-两者都实现为双向链接列表(尽管如果您想要的只是元素的有序集合,则可能应使用更通用的接口java.lang.List<T>
)
You can also use java.util.LinkedList<T>
for your implementation of deque<T>
. 您也可以将java.util.LinkedList<T>
用于deque<T>
。 java.util.LinkedList<T>
implements all the functions necessary for a queue/stack. java.util.LinkedList<T>
实现队列/堆栈所需的所有功能。
The reason NetBeans is telling you Vector<T>
is deprecated is because it is usually a better idea to use the data structures introduced by the Java Collections API. NetBeans告诉您不赞成Vector<T>
原因是,使用Java Collections API引入的数据结构通常是一个更好的主意。 In the place of Vector<T>
place, you should be using things like java.util.ArrayList<T>
or java.util.LinkedList<T>
. 在Vector<T>
位置,您应该使用java.util.ArrayList<T>
或java.util.LinkedList<T>
。
For vector, list and dequeue and other Collections take a look at this http://download.oracle.com/javase/tutorial/collections/index.html 对于vector,list和dequeue以及其他Collection,请查看以下http://download.oracle.com/javase/tutorial/collections/index.html
You may also find those classes interesting: InputStream, OutputStream, BufferedReader, BufferedWriter and StringBuilder. 您可能还会发现那些有趣的类:InputStream,OutputStream,BufferedReader,BufferedWriter和StringBuilder。
如果我没看错,Vector甚至比ArrayList还要慢,因为它是同步的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.