Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdc170a8

Browse files
committed
Add two new blogposts
1 parentcaf8736 commitdc170a8

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
layout:post
3+
title:"How To Create UUID in Java?"
4+
author:gaurav
5+
image:assets/images/2020-12-23/create-uuid-in-java.png
6+
categories:[ Java, Core Java, String]
7+
description:In this article you will see, how to create UUID in Java.
8+
9+
---
10+
11+
##Introduction
12+
13+
UUID, a universally unique identifier is a 128-bit number used to identify information in computer systems.
14+
15+
UUID is made of hex digits along with 4 hyphen ("-") symbols. The length of a UUID is 36 characters.
16+
17+
There are 5 types of UUID but mostly version 4 i.e. Randomly Generated UUID is used.
18+
19+
We are going to create the version 4 UUID here.
20+
21+
###Example UUID
22+
23+
df6fdea1-10c3-474c-ae62-e63def80de0b
24+
25+
##How to create UUID in Java?
26+
27+
Creating a Randomly Generated UUID (version 4) is really easy in Java.
28+
29+
UUID Class is present in`java.util` package. And it has the static method`randomUUID()` which returns the randomly generated UUID.
30+
31+
The example is given below.
32+
33+
```java
34+
importjava.util.UUID;
35+
36+
/**
37+
* A Java program to create a Randomly Generated UUID i.e. Version 4 UUID
38+
*@author Gaurav Kukade at coderolls.com
39+
*
40+
*/
41+
publicclassCreateUUID {
42+
43+
publicstaticvoidmain(String[]args) {
44+
45+
// creating random uuid i.e. version 4 UUID
46+
UUID uuid=UUID.randomUUID();
47+
48+
System.out.println("Printing the randomly generated UUID value......\n");
49+
50+
System.out.println("uuid:"+uuid);
51+
52+
}
53+
54+
}
55+
56+
```
57+
Output
58+
```java
59+
Printing the randomly generatedUUID value......
60+
61+
uuid: e3aed661-ccc2-42fd-ad69-734fee350cd2
62+
63+
```
64+
65+
Get the[above code as GitHub Gist](https://gist.github.com/gauravkukade/395f314c549969bd300d72c7e032dbcb).
66+
67+
--------
68+
69+
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.
70+
71+
If you found this article worth, support me by[giving a cup of Coffee ☕](https://www.paypal.me/GauravKukade)
72+
73+
####Related Articles
74+
75+
-[Learn About Java String Pool And intern() Method](https://coderolls.com/java-string-pool-and-intern-method/)
76+
-[How Do I Compare Strings In Java](https://coderolls.com/compare-strings-in-java/)
77+
-[How To Reverse A String In Java (5 ways)](https://coderolls.com/reverse-a-string-in-java/)
78+
-[Compare Two Strings Lexicographically In Java](https://coderolls.com/compare-two-strings-lexicographically-in-java/)
79+
-[Difference Between StringBuffer and StringBuilder class](https://coderolls.com/difference-between-stringbuffer-and-stringbuilder/)
80+
81+
-[8 Basic GIT Commands Every Newbie Developer Must Know](https://coderolls.com/basic-git-commands/)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
layout:post
3+
title:"How To Convert StringBuilder To String In Java?"
4+
author:gaurav
5+
image:assets/images/2020-12-25/convert-stringbuilder-to-string-in-java.png
6+
categories:[ Java, Core Java, String]
7+
description:In this article you will see, how to convert a StringBuilder to String in Java.
8+
featured:false
9+
---
10+
11+
##Introduction
12+
13+
Java`StringBuilder` is non-synchronized update of the`StringBuffer` class.
14+
15+
Sometimes there is need to convert the`StringBuilder` object to the`String`. We can do it easily by smply invoking the`toString()` method.
16+
17+
Let see the example program below.
18+
19+
##Java Program to convert`StringBuilder` to`String`
20+
21+
```java
22+
/**
23+
* A Java program to convert StringBuilder to String
24+
*@author Gaurav Kukade at cderlls.com
25+
*
26+
*/
27+
publicclassStringBuilderToString {
28+
29+
publicstaticvoidmain(String[]args) {
30+
StringBuilder stringBuilder=newStringBuilder("Hello");
31+
32+
stringBuilder.append("Gaurav")
33+
.append("Kukade!");
34+
35+
System.out.println("Printing strinBuilder as String:\n");
36+
System.out.println(stringBuilder.toString());
37+
38+
}
39+
40+
}
41+
```
42+
Output:
43+
```java
44+
Printing strinBuilder asString:
45+
46+
HelloGauravKukade!
47+
48+
```
49+
Get the[above code as GitHub Gist](https://gist.github.com/gauravkukade/00bd416bcb2ca1c72dbcd600d48e2f78).
50+
51+
---------
52+
53+
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.
54+
55+
If you found this article worth, support me by[giving a cup of Coffee ☕](https://www.paypal.me/GauravKukade)
56+
57+
####Related Articles
58+
59+
-[Learn About Java String Pool And intern() Method](https://coderolls.com/java-string-pool-and-intern-method/)
60+
-[How Do I Compare Strings In Java](https://coderolls.com/compare-strings-in-java/)
61+
-[How To Reverse A String In Java (5 ways)](https://coderolls.com/reverse-a-string-in-java/)
62+
-[Compare Two Strings Lexicographically In Java](https://coderolls.com/compare-two-strings-lexicographically-in-java/)
63+
-[Difference Between StringBuffer and StringBuilder class](https://coderolls.com/difference-between-stringbuffer-and-stringbuilder/)
64+
65+
-[8 Basic GIT Commands Every Newbie Developer Must Know](https://coder
34.8 KB
Loading

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp