Simple Problems... :(

Let's say I have a Long variable named x and a string variable named n
How do I add them together?

Long seed;
String n;

seed = seed + n

I know I need something kind of like
seed = seed + Long.getLong(n)
But I can't add and stuff.. :o
(I don't want a string, I want a long result...)
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Presumably you meant for seed to be a primite of type long (rather than an instance of class Long). In that case you could add n to seed by doing:


It's kind of the reverse of the toString method in those classes.
Nicolas_St_AmourAuthor Commented:
If I want to put that value in an array of int, how can I do that?

hmmm... let's say

Array[x] = seed + Long.parselong(n);

How can I make such a statement possible?
You just need to give it an explicit cast:

int Array[]=new int[50];
int x=2;

This will put the integer portion of "seed+n" into Array[x]. The fractional portion will be lost.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.