Can I convert String to Integer in J2ME?

Can I convert String to Integer in J2ME?

I retreive a record from recordStore and want to convert the record to Interger and pass to another class.. Is this possible?
redcoderAsked:
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.

CEHJCommented:
Integer i = new Integer("3");
0

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
redcoderAuthor Commented:
Or to make it easier , I will pass the record to second class and convert it to Integer in that second class
0
Mayank SAssociate Director - Product EngineeringCommented:
Integer i = new Integer ( new String ( recordStore.getRecord ( recordID ) ) ) ;
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

redcoderAuthor Commented:
 public Integer getLastQuest()
  {
   
    try
    {
          Integer numOfRcd = new Integer(recordStore.getNumRecords());
   
   
          return numOfRcd;
    }
    catch (Exception e)
    {
      e.printStackTrace();
      return numOfRcd;
    }
   
  }

gives me error:


 cannot resolve symbol
symbol  : variable numOfRcd
location: class PersistantData
      return numOfRcd;
0
CEHJCommented:
Integer numOfRcd = null;
try
    {
         numOfRcd = new Integer(recordStore.getNumRecords());
   
   
         return numOfRcd;
    }

.........
0
TimYatesCommented:
public Integer getLastQuest()
  {
    Integer numOfRcd = null ;
    try
    {
         numOfRcd = new Integer(recordStore.getNumRecords());
         return numOfRcd;
    }
    catch (Exception e)
    {
        e.printStackTrace();
        return numOfRcd;
    }
  }
0
TimYatesCommented:
Even neater:

  public Integer getLastQuest()
  {
      Integer numOfRcd = null ;
      try
      {
         numOfRcd = new Integer(recordStore.getNumRecords());
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
      return numOfRcd;
  }
0
TimYatesCommented:
so that will return null on exception
0
Mayank SAssociate Director - Product EngineeringCommented:
Why to return from the try/ catch block as well? Better to write the return statement only once, outside both of them :) that's how some companies' coding-standards mandate anyway ;-)
0
Mayank SAssociate Director - Product EngineeringCommented:
Oh :)
0
redcoderAuthor Commented:
Can i perform calculation on this Integer type?or should i use int type?
0
Mayank SAssociate Director - Product EngineeringCommented:
You can't. You need to use int.
0
redcoderAuthor Commented:
so can i convert Integer to int? and how?
0
Mayank SAssociate Director - Product EngineeringCommented:
Integer integerObj = new Integer ( value from record-store ) ;
int i = integerObj.intValue () ;
0
CEHJCommented:
int i = x.intValue();
0
Mayank SAssociate Director - Product EngineeringCommented:
Sorry, I didn't check that on J2ME. Will have to see if the method-name is the same. I hope so (you can check).
0
Mayank SAssociate Director - Product EngineeringCommented:
I'm assuming: "value from record-store" is not an 'int' otherwise you already have the 'int' there. If you are using recordStore.getNumRecords (), I guess it returns an 'int' anyway. If you have a String from the record-store and you want to convert it to an 'int', you can either make an Integer object and use intValue () as shown, or simply use Integer.parseInt ( stringValue ) ;
0
CEHJCommented:
:-)
0
Mayank SAssociate Director - Product EngineeringCommented:
>> int i = x.intValue();

Was that any different from what I posted just before it?
0
redcoderAuthor Commented:
Sorry, I didn't try on it.. I just use it cause its simple...
0
redcoderAuthor Commented:
Hi mayankeagle,

I see your point... basically you have
int i = integerObj.intValue () ;  similar to int i = x.intValue();

Sorry I didn't realize that... I should have split the point to you.. I made a mistake..
Do you want me to write to Admin to change it ? But I am not sure it is allowable or not?

My apologize...

:-|
0
Mayank SAssociate Director - Product EngineeringCommented:
It is possible. I have asked Venabili, our page-editor, to do it:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21765176.html
0
redcoderAuthor Commented:
Hi mayankeagle ,
I have request for edit in the following topic:

http://www.experts-exchange.com/Community_Support/Feedback/Q_21788589.html
0
redcoderAuthor Commented:
Hi CEHJ,

I hope you understand the situation, due to the policy that first come first rewarded.
0
CEHJCommented:
Don't worry
0
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
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.