Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1
Add new blogpost, how to convert an int to string in java#18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion_posts/java-string/2020-01-05-convert-string-to-int.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions_posts/java-string/2021-02-27-convert-int-to-string.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| --- | ||
| layout: post | ||
| title: "How To Convert An Integer To String In Java" | ||
| author: gaurav | ||
| image: assets/images/2021-02-27/convert-int-to-string.webp | ||
| categories: [Java, Core Java, String] | ||
| description: "In this article you are going to learn how can you convert an integer to a String." | ||
| --- | ||
| In this article you are going to learn how can you convert an integer to a String. | ||
| There are multiple ways we can convert an int to string in java. let's check what are they. | ||
| 1. `String.ValueOf()` method | ||
| 2. `Integer.toString()` method | ||
| 3. String.format() method | ||
| ## 1. `String.valueOf()` method | ||
| `String.valueOf()` method returns the string representation of the `Object` argument. | ||
| So when we pass an int as parameter to `valueOf()` method, it returns it's String representation. | ||
| If the argument is `null`, then a string equal to `"null"`will be returned. | ||
| Internally `valueOf()` method calls `toString()` method on the object argument to get its string representation. | ||
| An example to convert an int to string using `valueOf()` method is given below. | ||
| ```java | ||
| /* | ||
| * A program to convert an int to string in java using | ||
| * the String.toSTring() method. | ||
| * | ||
| * @author Gaurav Kukade at coderolls.com | ||
| */ | ||
| public class IntToSTring{ | ||
| public static void main(String []args){ | ||
| int number = 1234; | ||
| String numberString = String.valueOf(number); | ||
| //print string value of number | ||
| System.out.println("numberString: " + numberString); | ||
| } | ||
| } | ||
| ``` | ||
| Output | ||
| ```java | ||
| numberString: 1234 | ||
| ``` | ||
| ## 2. `Integer.toString()` method | ||
| `Integer.toString()` method returns the String object of the Integer's value. | ||
| The value is converted to signed decimal representation and returned as a string, exactly as if the integer value were given as an argument to the `toString()` method. | ||
| An example to convert an int to string using the `toString()` method is given below. | ||
| ```java | ||
| /* | ||
| * A program to convert an int to string in java using | ||
| * the Integer.toString() method. | ||
| * | ||
| * @author Gaurav Kukade at coderolls.com | ||
| */ | ||
| public class IntToSTring{ | ||
| public static void main(String []args){ | ||
| int number = 1234; | ||
| //String numberString = String.valueOf(number); | ||
| String numberString = Integer.toString(number); | ||
| //print string value of number | ||
| System.out.println("numberString: " + numberString); | ||
| } | ||
| } | ||
| ``` | ||
| Output | ||
| ```java | ||
| numberString: 1234 | ||
| ``` | ||
| If you found this article worth, support me by [giving a cup of Coffee ☕](https://www.paypal.me/GauravKukade) | ||
| ### Related Articles | ||
| - [How to convert String to Integer in Java](https://coderolls.com/convert-string-to-int/) | ||
| - [Learn About Java String Pool And intern() Method](https://coderolls.com/java-string-pool-and-intern-method/) | ||
| - [How Do I Compare Strings In Java](https://coderolls.com/compare-strings-in-java/) | ||
| - [How To Reverse A String In Java (5 ways)](https://coderolls.com/reverse-a-string-in-java/) | ||
| - [Compare Two Strings Lexicographically In Java](https://coderolls.com/compare-two-strings-lexicographically-in-java/) | ||
| - [Difference Between StringBuffer and StringBuilder class](https://coderolls.com/difference-between-stringbuffer-and-stringbuilder/) | ||
| - [8 Basic GIT Commands Every Newbie Developer Must Know](https://coderolls.com/basic-git-commands/) |
7 changes: 3 additions & 4 deletions_posts/java-uuid/2020-12-23-create-uuid-in-java.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Binary file addedassets/images/2021-02-27/convert-int-to-string.webp
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.