-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathSort_the_String.java
35 lines (29 loc) · 951 Bytes
/
Sort_the_String.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Arrays;
// Main class
public class GFG {
// Method 1
// To sort a string alphabetically
public static String sortString(String inputString)
{
// Converting input string to character array
char tempArray[] = inputString.toCharArray();
// Sorting temp array using
Arrays.sort(tempArray);
// Returning new sorted string
return new String(tempArray);
}
// Method 2
// Main driver method
public static void main(String[] args)
{
// Custom string as input
String inputString = "geeksforgeeks";
String outputString = sortString(inputString);
// Print and display commands
// Input string
System.out.println("Input String : " + inputString);
// Output string
System.out.println("Output String : "
+ outputString);
}
}