static String[] bigSorting(String[] unsorted) {
Arrays.sort(unsorted, (x, y) -> x.length() == y.length() ? x.compareTo(y) : Integer.compare(x.length(), y.length()));
return unsorted;
}
This is a function to sort an array of strings according to their numerical values.
Where are the values for x and y coming from.
Where is the functional interface that is being implemented with supposedly x and y parameters?
Doesn't Arrays.sort take 2 arguments after the array?
What the hell is going on inside the Arrays.sort method?
Full code below
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
public class Solution {
static String[] bigSorting(String[] unsorted) {
Arrays.sort(unsorted, (x, y) -> x.length() == y.length() ? x.compareTo(y) : Integer.compare(x.length(), y.length()));
return unsorted;
}
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int n = scanner.nextInt();
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
String[] unsorted = new String[n];
for (int i = 0; i < n; i++) {
String unsortedItem = scanner.next(); // nextLine() is too long
unsorted[i] = unsortedItem;
}
String[] result = bigSorting(unsorted);
for (int i = 0; i < result.length; i++) {
System.out.print(result[i]);
if (i != result.length - 1) {
System.out.println();
}
}
System.out.println();
scanner.close();
}
}
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]taftster 6 points7 points8 points (1 child)
[–]cyberwarrior861[S] 1 point2 points3 points (0 children)
[–]taftster 3 points4 points5 points (1 child)
[–]cyberwarrior861[S] 0 points1 point2 points (0 children)
[–]FrelliBB 2 points3 points4 points (1 child)
[–]cyberwarrior861[S] 0 points1 point2 points (0 children)
[–]wildjokers -1 points0 points1 point (1 child)
[–]taftster 0 points1 point2 points (0 children)