简体   繁体   English

C ++到Java,语言等效问题

[英]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 ++中,我非常喜欢Stringstreamvectorlistdequeue ,但是还没有找到足够的文档。 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.

相关问题 为什么说Java语言是在C,C ++之上开发的? - Why is it said that the java language was developed on top of C, C++? Android开发的C ++问题 - C++ questions for android development D转换器:有没有办法将D语言转换为java或C ++? - D converter: Is there a way to convert D language to java or C++? OpenCv Java:与Java等价的Matlab代码 - OpenCv Java : Matlab code to Java equivalency OpenCV C ++代码转换为Java语言“简单形状检测应用程序” - OpenCV C++ code to Java Language “Simple Shape Detection App” 如何转换“ArrayList <ClassNod> “用Java编写成C ++程序语言? - How to convert an “ArrayList<ClassNod>” written in Java into a C++ program language? C ++(Intel)vs Java(Hotspot)与C#基准测试问题(包括代码和结果) - C++ (Intel) vs Java (Hotspot) vs C# benchmark questions (code and results included) 是否有类似 C 的迷你语法/语言可以翻译成原生 C/C++ 和 Java? - Is there a C-like mini-syntax/language that can be both translated to native C/C++ and Java? C ++语言记忆模型 - C++ language memory model 使用本机语言是 C 或 C++ 的 JNI 接口在 Java 中实现 USB 通信是个好主意吗? - Is it good idea to implement USB communication in Java using JNI interface where native language is C or C++?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM