5
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by ~s.o.s~
0

Assuming you know the index of the element to be converted do:

int anInt = Integer.parseInt(vector.get(index));
0

> how can you convert a string, which is stored in a vector, into an
> integer?

Consider searching the archives on the web as a first resort before posting a question. This question has already been answered numerous times. It'll save you a lot of time and will be a step forward in making you an independent/better programmer.

0

how can you convert a string, which is stored in a vector, into an integer?

the best answer here would be: don't

if it's stored as a String, it may very well contain a numeric value that exceeds the limits of an int
if it's stored as a String, it may also contain non-numeric values

0

the best answer here would be: don't

if it's stored as a String, it may very well contain a numeric value that exceeds the limits of an int
if it's stored as a String, it may also contain non-numeric values

And what happens if he NEEDS to, then why not perform some error checking before conversion?

0

Or of course there is the NumberFormatException which gets thrown if the conversion was unsuccessful, no matter the reason.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.