Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 09-11-2009
Member
 
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.
Reply With Quote
  #2  
Old 09-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
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.
Reply With Quote
  #3  
Old 09-11-2009
Member
 
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);
  }
}
Reply With Quote
  #4  
Old 09-11-2009
Member
 
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);
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to convert string into int in Java"
Thread Thread Starter Forum Replies Last Post
How to convert string to char array in java? Baazigar Software Development 6 10-01-2011 06:36 PM
Convert string to binary in java TechGate Software Development 5 28-01-2010 01:36 PM
How to convert InputStream to String in java? KALIDA Software Development 4 20-01-2010 06:16 PM
How to convert String to Date object in java? KALANI84 Software Development 4 20-01-2010 05:07 PM
how to convert a boolean value to a string in java? Janus Software Development 3 29-07-2009 08:07 PM


All times are GMT +5.5. The time now is 01:44 PM.