Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer question correctly and show the result of the working code. The ac

ID: 3749455 • Letter: P

Question

Please answer question correctly and show the result of the working code. The actual and demo code is provided .must take command line arguments of text files for ex : input.txt output.txt from a filetext(any kind of input for the text file should work as it is for testing the question)

This assignment is about using the Java Collections Framework to accomplish some basic text-processing tasks.

These questions involve choosing the right abstraction (Collection, Set, List, Queue, Deque, SortedSet, Map, or SortedMap) to efficiently accomplish the task at hand. The best way to do these is to read the question and then think about what type of Collection is best to use to solve it. There are only a few lines of code you need to write to solve each of them.

Unless specified otherwise, sorted order refers to the natural sorted order on Strings, as defined by String.compareTo(s).

Explanation / Answer

SortedMap is an interface in accumulation system. This interface expands Map inrerface and gives an aggregate requesting of its (components can be navigated in arranged request of keys). Exampled class that actualizes this interface is TreeMap.

sortedmap

The primary normal for a SortedMap is that, it arranges the keys by their common requesting, or by a predetermined comparator. So consider utilizing a TreeMap when you need a guide that fulfills the accompanying criteria:

invalid key or invalid esteem are not allowed.

The keys are arranged either by common requesting or by a predefined comparator.

Strategies for SortedMap:

subMap(K fromKey, K toKey): Returns a perspective of the segment of this Map whose keys go from fromKey, comprehensive, to toKey, selective.

headMap(K toKey): Returns a perspective of the bit of this Map whose keys are entirely not as much as toKey.

tailMap(K fromKey): Returns a perspective of the part of this Map whose keys are more noteworthy than or equivalent to fromKey.

firstKey(): Returns the primary (least) enter as of now in this Map.

lastKey(): Returns the last (most astounding) enter right now in this Map.

comparator(): Returns the Comparator used to arrange the keys in this Map, or invalid if this Map utilizes the common requesting of its keys.

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
  
public class example
{
public static void main(String[] args)
{
SortedMap<Integer, String> sorted_Map =
new TreeMap<Integer, String>();
sorted_Map.put(new Integer(2), "second statement");
sorted_Map.put(new Integer(3), "third statement");
sorted_Map.put(new Integer(5), "fifth statement");
sorted_Map.put(new Integer(4), "fourth statement");
sorted_Map.put(new Integer(1), "first statement");
Set s = sorted_Map.entrySet();
  
Iterator i = s.iterator();
  
while (i.hasNext())
{
Map.Entry mp = (Map.Entry)i.next();
  
int key = (Integer)mp.getKey();
String value = (String)mp.getValue();
  
System.out.println("Key : " + key +
" value : " + value);
}
}
}