Posts

Showing posts with the label Java-Tutorials

How to convert Float to String in Java?

ss In last post, we have learned how to convert string to float in java. In this post, we are going to learn how to convert float to string in Java. Consider the situation, if we want to display float value is any text area or if we want to do any manipulation using float value, conversion of float to string is need to be known. Conversion of float to string in java can be done in  following ways: toString(float f) It is a static method of float class. It provides a string representation of float value. If float value is NaN, then result in String is NaN. Else, it will provides string representation of float. For more detailed about this method. public static String toString(float f) Parameter   f - float value Returns a string representation of float value. valueOf() It is a static method of String class. It returns string representation of float argument. public static String valueOf(float f)

How to convert String to Float in Java?

In Java understanding of all data types conversion is helpful in many ways. In this post, we are going to learn how to covert string to float in java Consider the scenario, if you are receiving float value using text field or text area, the float value is stored in the form of string. Then at that place there is a need to convert string to float for further operations. parseFloat(String s) It is used to convert a float value stored in a string to a float variable. It is a static method of float class. public static float parseFloat(String s) throws NumberFormatException Parameters s - a string to be parsed Returns returns a float value Exception if a string cannot be parsed throws NumberFormatException valueOf(String s) It is also one of static method of float class. If string is null, throws NullPointer Exception public static float valueOf(String s) throws NumberFormatException Parameters s - a string to be parsed Returns returns a float val

How to convert Int to String in Java?

In this article we are going to learn about how to convert int to string in java. It is necessary to know type conversion because, when a number is converted to string it is useful for many easy manipulation. In this you will find all the ways to convert int to string in java and at end of article you will find code containing all learned methods. Integer.toString(int num) It is one of best method to remember, because toString() has ability to convert any data type to string representation. It is also used to provide the string representation of entire class in default way and if you want to retrieve in your wish, then you can override that method and we will discuss about this later on another topic. public static String toString(int num) Parameters num, a integer   Returns string representation of any data type valueOf(int num) It is also another best method which has ability to covert to any data type. valueOf() returns string containing a number.

How to convert String to Int in Java?

In Java, a number stored in a string can be used to do longest operations in easiest way such as removing duplicates etc. Also String has the capacity to store big integers also. But in some cases it will be useful if you know about type conversion between all data types. Here in this topic we are going to learn about the conversion of number stored in a string to integer in java. Also, along with that method explanation, there is a final code at end which contains both method conversion. A string can be converted int in Java in following ways. parseInt(String s)   The characters in string must be decimal digits excepts character at 0. At 0, it can be ASCII '- or +' to indicate sign of numbers. public static int parseInt (String s) throws NumberFormatException Parameters s - which is of type string containing digits Returns Returns the number of Integer type Exception Throws NumberFormatException , if the string does not contain parsable Integers val