HunderingThooves
HunderingThooves

Reputation: 992

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:

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. When I try to use Vector, netbeans tells me that it's deprecated, does that mean some other code took it's place? Is there some other container I should be using instead?

Thanks!

Upvotes: 2

Views: 166

Answers (3)

If I'm not wrong, Vector is even slower than ArrayList because it is synchronized.

Upvotes: 0

Jack Edmonds
Jack Edmonds

Reputation: 33171

For Stringstream you can use java.io.ByteArrayOutputStream

C++'s Vector<T> is basically the same as 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>)

You can also use java.util.LinkedList<T> for your implementation of deque<T>. java.util.LinkedList<T> implements all the functions necessary for a queue/stack.

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. In the place of Vector<T> place, you should be using things like java.util.ArrayList<T> or java.util.LinkedList<T>.

Upvotes: 5

pablosaraiva
pablosaraiva

Reputation: 2343

For vector, list and dequeue and other Collections take a look at this http://download.oracle.com/javase/tutorial/collections/index.html

You may also find those classes interesting: InputStream, OutputStream, BufferedReader, BufferedWriter and StringBuilder.

Upvotes: 1

Related Questions