Computers and Technology

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);

}

}

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 06:50, phillipfruge3
Match the personality traits with their description
Answers: 1
image
Computers and Technology, 22.06.2019 23:00, brooklynmikestovgphx
Suppose s, t, and w are strings that have already been created inside main. write a statement or statements, to be added to main, that will determine if the lengths of the three strings are in order by length, smallest to largest. that is, your code should determine if s is strictly shorter than t, and if t is strictly shorter than w. if these conditions hold your code should print (the boolean value) true. if not, your code should print false. (strictly means: no ties) example: if s, t, and w are "cat", "hats", and "skies" your code should print true - their lengths are 3-4-5; but if s, t, and w are "cats" "shirt", and "trust", then print false - their lengths are 4-5-5 enter your code in the box below
Answers: 2
image
Computers and Technology, 23.06.2019 18:50, annieleblanc2004
Ais a picture icon that is a direct link to a file or folder
Answers: 1
image
Computers and Technology, 24.06.2019 01:00, bellamyciana
What are two ways to access the options for scaling and page orientation? click the home tab, then click alignment, or click the file tab. click the file tab, then click print, or click the page layout tab. click the page layout tab, or click the review tab. click the review tab, or click the home tab?
Answers: 2
Do you know the correct 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, 20.09.2020 16:01