I need help with Java #\'s 5-9 public static HashMaR buildLastNametoFirstNameMap
ID: 3883099 • Letter: I
Question
I need help with Java #'s 5-9
public static HashMaR buildLastNametoFirstNameMap(String[] tullNames) { /* fullNames is an array of entries all in the format "FirstName, LastName", a first name and a last name separated by a space. This function should return a map where the keys are the LastNames from the input array and the corresponding value is the associated FirstName. You may assume each LastName only occurs once in the input array. */ **Test input: an empty array: an array containing "Barry White" and "Bob Marley" public staic HashMa > buildLastName To FirstNamesMap(String[] fullNames) { /* fullNames is an array of entries all in the format "FirstName LastName", a first name and a last name separated by a space. This function should return a map where the keys are the LastNames from the input array and the corresponding value is a list of all the FirstNames that appeared with that LastNames in the input array. */ **Test input: an empty array: an array containing "Barry White" and "Bob Marley'': an array containing "Barry White", "Bob Mariey" and "Betty White". public static boolean isPermutation(String string1, String string2) { /* This functions should return true if string 1 is a permutation of string2. In this case you should assume that means contains exactly the same characters, same case, including spaces. You may assume string1 and string2 only contain the 128 ascii characters, no unicode. For this question, you should optimize for very long input strings. */ Test input: 2 empty Strings: "ab" "ba": "abc" "asd": **rats** "star"*** public static boolean isPermutationFast(String string1, String string2) { /* This functions should return true if string1 is a permutation of string2. In this case you should assume that means contains exactly the same characters, same case, including spaces. The strings may contain ascii or unicode, characters. For this question, you should optimize for speed and very long input strings. */ } **Test input: 2 empty Strings: ab" "ba" "abc" "acd": **rats** *star**: *lu263A BYE NOW!!" "BYE NOW! u263A" public static boolean isPermutationLight(String string1, String string2) { /*(This functions should return true if stnng1 is a permutation of string2. In this case you should assume that means contains exactly the same characters, same case, including spaces. The strings may contain ascii or unicode characters. For this question, you should optimize for space and fairly short input strings. */ ** Test input: Same as #8Explanation / Answer
5.
import java.util.HashMap;
public class BuildStrings {
public static HashMap<String, String> buildLastNameToFirstNameMAp(String[] fullnames)
{
HashMap<String, String> lastToFirstName = new HashMap<>();
for(String name: fullnames)
{
String[] parts = name.split("\s+");
lastToFirstName.put(parts[1], parts[0]);
}
return lastToFirstName;
}
public static void main(String[] args)
{
String[] arr1 = new String[0];
HashMap<String, String> lastToFirstName = buildLastNameToFirstNameMAp(arr1);
String[] arr2 = new String[2];
arr2[0] = "Barry White";
arr2[1] = "Bob Marley";
lastToFirstName = buildLastNameToFirstNameMAp(arr2);
}
}
Please post one question at a time.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.