sort a string array java
String[] myArray = {"JavaFX", "HBase", "OpenCV", "Java", "Hadoop","Neo4j"};
Arrays.sort(myArray);
System.out.println(Arrays.toString(myArray));
sort a string array java
String[] myArray = {"JavaFX", "HBase", "OpenCV", "Java", "Hadoop","Neo4j"};
Arrays.sort(myArray);
System.out.println(Arrays.toString(myArray));
string sorting in java
public class ArrayReturn3 {
public static String[] sortNames(String[] userNames) {
String temp;
for (int i = 0; i < userNames.length; i++) {
for (int j = i + 1; j < userNames.length; j++) {
if (userNames[i].compareTo(userNames[j]) > 0) {
temp = userNames[i];
userNames[i] = userNames[j];
userNames[j] = temp;
}
}
}
return userNames;
}
public static void main(String[] args) {
String[] names = {"Ram", "Mohan", "Sohan", "Rita", "Anita", "Nita", "Shyam", "Mukund"};
System.out.println("Names before sort");
for (String n : names) {
System.out.print(" " + n);
}
String[] sortedNames = sortNames(names);
System.out.println("\nNames after sort (Sent name)");
for (String n : names) {
System.out.print(" " + n);
}
System.out.println("\nNames after sort (Received name)");
for (String n : sortedNames) {
System.out.print(" " + n);
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us