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

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 20:00
An excel which cell contains =b2 is copied to row below, the same column. what will be the new cell's content
Answers: 2
question
Computers and Technology, 22.06.2019 09:40
Sarah is having a hard time finding a template for her advertising business that she may be able to use at a later date and also make it available to her colleagues
Answers: 1
question
Computers and Technology, 22.06.2019 12:10
1. declare a constant named cents_per_pound and initialize with 25. 2. get the shipping weight from user input storing the weight into shipweightpounds. 3. using flat_fee_cents and cents_per_pound constants, assign shipcostcents with the cost of shipping a package weighing shipweightpounds.
Answers: 2
question
Computers and Technology, 22.06.2019 19:10
What a backup plan that you have created in a event you encounter a situation
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
question
Mathematics, 21.03.2021 08:30
question
History, 21.03.2021 08:30
question
Mathematics, 21.03.2021 08:30
question
Mathematics, 21.03.2021 08:30
question
Mathematics, 21.03.2021 08:40