How to Sort the String using string Method In java

Java have a lot of method for string operations. We can sort a string by convert in to array of characters , now we will sort array after that we will make a new string from sorted array.Now our new string is in sorted order of characters.

package com.javaproficiency;

import java.util.Arrays;

public class StringSort {

public static void main(String[] args) {
String str = “xyabds”;
char [] arr = str.toCharArray();
String sortedStr = new String(arr);
System.out.println(” sorted string = “+sortedStr);



sorted string = abdsxy

Leave a Reply

Your email address will not be published. Required fields are marked *

20 − 13 =