String to Integer


In JAVA programming it is very frequent demand of converting an int/Integer to String.

Below snapshot shows how this is done. Easy to remember.
Integer to String

public class DataTypeCoversionDemo {
            private static String strVar = "11";
            private static int intVar = 22;
            private static Integer integerVar = 222;
     
      public static void main(String[] args) {      
          convertInt_String();   
      }

      public static void convertInt_String(){
            // ********* Integer to int ********** //
            Integer tInteger = Integer.valueOf(intVar);
            int tSimpleIntValue = tInteger.intValue();

            System.out.println("Simple Int to Integer  :- " + tInteger); //22      
            System.out.println("Integer to Simple int :- " + tSimpleIntValue); //22

            // ********* int to String ********* //
            String tString = String.valueOf(intVar);
            int tInt = Integer.parseInt(strVar);

            System.out.println("Simple Int to String :- " + tString); //22
            System.out.println("String to Simple Int :- " + tInt); //11

            // ******* Integer to String ******* //  
            String tString2 = integerVar.toString();
            Integer tInteger2 = Integer.parseInt(strVar);        

            System.out.println("Integer to String :- " + tString2); //222
            System.out.println("String to Integer :- " + tInteger2); //11
      }
}
Advertisements

11 comments on “String to Integer

  1. Rattling superb info can be found on this blog.

  2. filtri says:

    filtri
    Hey, can I use your article on my blog with a linkback?

  3. http://magicofmakingupx.WebStarts.com Thanks for that awesome posting. It saved MUCH time 🙂

  4. motornaolja says:

    bolha
    Thanks for your input and I will use it for my school research that I am doing for this website.

  5. Haddix says:

    I really enjoy the article.Thanks Again. Keep writing.

  6. Vada says:

    Hi there, I found your website by the use of
    Google while looking for a comparable topic, your site came
    up, it looks good. I have bookmarked it in my google bookmarks.

    Hi there, just became aware of your blog thru Google, and found that it is really informative.
    I am going to watch out for brussels. I’ll appreciate in case you proceed this in future. A lot of folks can be benefited out of your writing. Cheers!

  7. Valeria says:

    It seems you actually know quite a bit related to this
    specific issue and this exhibits with this amazing
    post, called “String to Integer « SchoolHood”.
    Regards -Brianne

  8. Elliot says:

    What’s up colleagues, how is all, and what you would like to say on the topic of this article, in my view its in fact remarkable in favor of me.

  9. I wanted to thank you for this good read!! I certainly enjoyed every little bit
    of it. I have got you bookmarked to look at new stuff you post…

  10. Hey there! This is my first comment here so I just
    wanted to give a quick shout out and say I truly
    enjoy reading your articles. Can you recommend any
    other blogs/websites/forums that deal with the same topics?
    Thank you so much!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s