Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Long into a Vector Type 1

Status
Not open for further replies.

dcusick

Technical User
Aug 9, 2000
271
US
Hey everyone! I'm coming across a little problem with a program I'm working on. I am attempting to put a date(in milliseconds) into a vector object. The variable is long, and I keep getting errors. What can I do to get this to go? Do I have to cast it to a specific data type? Also, when I extract the value, how am I going to reconvert it back to a long, from the object variable. Any help would be greatly appreciated. Thanks.

Doug
 
Well I found my own answer... so here goes..

to get the long value ready to put into the vector, you do as follows...

long l;
Long.toString(l);

then to go the other way, from string to long, do as follows...

String s;
long l = Long.parseLong(s.trim());

Just in case anyone was wondering...

Doug
 
Another sollution:

long date;
Vector v=new Vector();

//Put date in the vector:
Long t=new Long(date);
v.addElement(t);


//Get date out of the vector:
date=((Long)v.elementAt(0)).longValue();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top