String Operation Using collection Framework
Sorting Order
public static void sortAccending(String s) {
char[] arr = s.toCharArray();
Arrays.sort(arr);
System.out.print(arr);
}
Sorting String Descending Order
public static void SortingDesendingOrder(String s) {
char[] arr = s.toCharArray();
Character[] a = new Character[arr.length];
for (int i = 0; i < a.length; i++)
a[i] = arr[i];
Arrays.sort(a, (o1, o2) -> { return -1;});
for (int i = 0; i < a.length; i++)
arr[i] = a[i];
System.out.print(arr);
}
RemoveDublicate Inside String
public static void RemoveDublicate(String s) {
Set<Character> s1 = new HashSet<>();
for(int i=0; i<s.length(); i++)
s1.add(s.charAt(i));
String temp = "";
for(char ch: s1) {
temp = temp+ch+"";
}
System.out.println(temp);
}
Other Logic
/* removeDublicate
* LinkedHashSet<Charactor> s = new LinkedHashSet<Charactor>();
int n = str.length();
for(int i=0; i<n; i++)
s.add(str.charAt(i));
System.out.println(s);
return str;
*/
No comments:
Post a Comment
If you have any doubt . Please let me know