Results 1 to 4 of 4

Thread: How to convert string into int in Java

  1. #1
    Join Date
    Apr 2009
    Posts
    87

    How to convert string into int in Java

    Can any one tell me the code in java to convert string to int. What are the syntax and declaration commands are used to convert string to int. Any help will be extremely appreciated.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    re: How to convert string into int in Java

    You can convert a Java String to an int using the parseInt() method of the Integer class.The toString() method also convert Integer number to string number. The java.lang package provides this conversion functionality through toString() method. String can be converted into int in java by parseInt() method. Type casting is a method to change string to integer.

  3. #3
    Join Date
    Jan 2009
    Posts
    199

    re: How to convert string into int in Java

    Code:
    import java.io.*;
    import java.lang.*;
    
    public class intst {
      public static void main(String[] avg) throws IOException{
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
        System.out.pn("Enter the value");
        String st = read.readLine();
        String d = new Integer(str).toString();
        System.out.pn("String:=" +d);
      }
    }

  4. #4
    Join Date
    Dec 2008
    Posts
    177

    re: How to convert string into int in Java

    string to int in java :
    Code:
    public class strtoint {
    
        public static void main(String[] avg) {
            String stint="1234";
    
            int M1=Integer.parseInt(str);
    			// method 1 to convert string to int
    
            System.out.println("Type no string to integer :"+rM1);
    
            int M2=Integer.valueOf(str);
    			
    
            System.out.prln("Type no string to integer :"+M2);

Similar Threads

  1. How to convert string to char array in java?
    By Baazigar in forum Software Development
    Replies: 6
    Last Post: 10-01-2011, 06:36 PM
  2. Convert string to binary in java
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 28-01-2010, 01:36 PM
  3. How to convert InputStream to String in java?
    By KALIDA in forum Software Development
    Replies: 4
    Last Post: 20-01-2010, 06:16 PM
  4. How to convert String to Date object in java?
    By KALANI84 in forum Software Development
    Replies: 4
    Last Post: 20-01-2010, 05:07 PM
  5. how to convert a boolean value to a string in java?
    By Janus in forum Software Development
    Replies: 3
    Last Post: 29-07-2009, 08:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,448,791.47128 seconds with 17 queries