subject

It is common for people to name directories as dir1, dir2, and so on. When there are ten or more directories, the operating system displays them in dictionary order, as dir1, dir10, dir11, dir12, dir2, dir3, and so on. That is irritating, and it is easy to fix. Provide a comparator that compares strings that end in digit sequences in a way that makes sense to a human. First compare the part before the digit as strings, and then compare the numeric values of the digits.

Your program should work with the provided test program Call the class you write DirectoryComparator. java.

import java. util. ArrayList;

import java. util. Arrays;

import java. util. Collections;

public class DirectorySortDemo

{

public static void main(String[] args)

{

String[] dirNames = {"dir12", "dir5", "dir9", "dir1", "dir4",

"lab10", "lab2", "lab7", "lab17", "lab8",

"quiz8", "quiz10", "quiz11", "quiz12",

"dir11", "dir8", "dir7", "dir15", "dir3"};

ArrayList directories = new ArrayList<>(Arrays. asList(dirNames));

System. out. println("Unsorted List:");

System. out. println(directories);

Collections. sort(directories, new DirectoryComparator());

System. out. println();

System. out. println("Sorted List:");

System. out. println(directories);

}

}

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 21:30, elsauceomotho
Im doing this last minute and literally none of my neighbors or people that my dad works with use excel so if anyone could me make up an example
Answers: 1
image
Computers and Technology, 23.06.2019 12:30, Prettygirlyaya
How is the brightness of oled of the diaplay is controled
Answers: 1
image
Computers and Technology, 23.06.2019 18:30, emmaishere69
List 3 items that were on kens resume that should have been excluded
Answers: 1
image
Computers and Technology, 23.06.2019 20:00, shaheedbrown06
What software programs are used to to create professional publication? a.) graphics programs b.) word processors c.) page layout programs d.) spreadsheet programs
Answers: 2
You know the right answer?
It is common for people to name directories as dir1, dir2, and so on. When there are ten or more dir...

Questions in other subjects:

Konu
Mathematics, 22.04.2020 19:34
Konu
Mathematics, 22.04.2020 19:34