diff --git a/_posts/2020-12-23-create-uuid-in-java.md b/_posts/2020-12-23-create-uuid-in-java.md new file mode 100644 index 0000000..e3369ab --- /dev/null +++ b/_posts/2020-12-23-create-uuid-in-java.md @@ -0,0 +1,81 @@ +--- +layout: post +title: "How To Create UUID in Java?" +author: gaurav +image: assets/images/2020-12-23/create-uuid-in-java.png +categories: [ Java, Core Java, String] +description: In this article you will see, how to create UUID in Java. + +--- + +## Introduction + +UUID, a universally unique identifier is a 128-bit number used to identify information in computer systems. + +UUID is made of hex digits along with 4 hyphen ("-") symbols. The length of a UUID is 36 characters. + +There are 5 types of UUID but mostly version 4 i.e. Randomly Generated UUID is used. + +We are going to create the version 4 UUID here. + +### Example UUID + +df6fdea1-10c3-474c-ae62-e63def80de0b + +## How to create UUID in Java? + +Creating a Randomly Generated UUID (version 4) is really easy in Java. + +UUID Class is present in `java.util` package. And it has the static method `randomUUID()` which returns the randomly generated UUID. + +The example is given below. + +```java +import java.util.UUID; + +/** + * A Java program to create a Randomly Generated UUID i.e. Version 4 UUID + * @author Gaurav Kukade at coderolls.com + * + */ +public class CreateUUID { + + public static void main(String[] args) { + + // creating random uuid i.e. version 4 UUID + UUID uuid = UUID.randomUUID(); + + System.out.println("Printing the randomly generated UUID value......\n"); + + System.out.println("uuid: "+uuid); + + } + +} + +``` +Output +```java +Printing the randomly generated UUID value...... + +uuid: e3aed661-ccc2-42fd-ad69-734fee350cd2 + +``` + +Get the [above code as GitHub Gist](https://gist.github.com/gauravkukade/395f314c549969bd300d72c7e032dbcb). + +-------- + +You can visit my [YouTube channel 'coderolls'](https://www.youtube.com/channel/UCl31HHUdQbSHOQfc9L-wo3w?view_as=subscriber?sub_confirmation=1) to find more video tutorials. + +If you found this article worth, support me by [giving a cup of Coffee ☕](https://www.paypal.me/GauravKukade) + +#### Related Articles + +- [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/) diff --git a/_posts/2020-12-25-convert-stringbuilder-to-string-in-java.md b/_posts/2020-12-25-convert-stringbuilder-to-string-in-java.md new file mode 100644 index 0000000..88ec9a0 --- /dev/null +++ b/_posts/2020-12-25-convert-stringbuilder-to-string-in-java.md @@ -0,0 +1,65 @@ +--- +layout: post +title: "How To Convert StringBuilder To String In Java?" +author: gaurav +image: assets/images/2020-12-25/convert-stringbuilder-to-string-in-java.png +categories: [ Java, Core Java, String] +description: In this article you will see, how to convert a StringBuilder to String in Java. +featured: false +--- + +## Introduction + +Java `StringBuilder` is non-synchronized update of the `StringBuffer` class. + +Sometimes there is need to convert the `StringBuilder` object to the `String`. We can do it easily by smply invoking the `toString()` method. + +Let see the example program below. + +## Java Program to convert `StringBuilder` to `String` + +```java +/** + * A Java program to convert StringBuilder to String + * @author Gaurav Kukade at cderlls.com + * + */ +public class StringBuilderToString { + + public static void main(String[] args) { + StringBuilder stringBuilder = new StringBuilder("Hello "); + + stringBuilder.append("Gaurav ") + .append("Kukade!"); + + System.out.println("Printing strinBuilder as String: \n"); + System.out.println(stringBuilder.toString()); + + } + +} +``` +Output: +```java +Printing strinBuilder as String: + +Hello Gaurav Kukade! + +``` +Get the [above code as GitHub Gist](https://gist.github.com/gauravkukade/00bd416bcb2ca1c72dbcd600d48e2f78). + +--------- + +You can visit my [YouTube channel 'coderolls'](https://www.youtube.com/channel/UCl31HHUdQbSHOQfc9L-wo3w?view_as=subscriber?sub_confirmation=1) to find more video tutorials. + +If you found this article worth, support me by [giving a cup of Coffee ☕](https://www.paypal.me/GauravKukade) + +#### Related Articles + +- [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://coder diff --git a/assets/images/2020-12-23/create-uuid-in-java.png b/assets/images/2020-12-23/create-uuid-in-java.png new file mode 100644 index 0000000..66b7686 Binary files /dev/null and b/assets/images/2020-12-23/create-uuid-in-java.png differ diff --git a/assets/images/2020-12-25/convert-stringbuilder-to-string-in-java.png b/assets/images/2020-12-25/convert-stringbuilder-to-string-in-java.png new file mode 100644 index 0000000..309540e Binary files /dev/null and b/assets/images/2020-12-25/convert-stringbuilder-to-string-in-java.png differ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy