[Solved]Java Possible Define Generic Methods Instance Given Example Demonstrates Simple Case Metho Q37148983
IN JAVA PLEASE


In Java, it is possible to define generic methods. For instance, given example demonstrates a simple case for a method, that takes an array of any type ava generics.h Problem L Implement a generic method, that takes an array list, containing any type, and prints out the elements, similar to the example. Note, that even though it is possible to just use ArrayList or ArrayList Object to achieve seemingly similar functionality, your method needs to be generic, so that it accepts a parameter like this: ArrayList<T> inputArrayList. Name your method printArray0 In most modern programming languages, it is possible to use lambda functions. Lambda function in this context is a function, that is defined in place where it is used. For instance, it can be used to sort a list, as shown in this examp ing-lam Collections.sort (personList, (Person pl, Person p2) > pl.firstName.compareTo (p2.firstName)) Problem 2. Based on the abovementioned concepts and solution to the problem 1, complete the following code import java.uti1.ArrayList; import java.util.Collections; public class TemplateMethodExampleMain public static int count (String text, String find) count -0, length int index = 0, while( (index find. length(); index))–1 ) text . index0f(find, { index length; count++; return count; // Your implementation of a generic printArray) method public static void main(String args]) ArrayList<String testList new ArrayList<String>); testList.add(“String #2°..); testList.add(“String #3**”); testList.add(“String #1 “); testList.add(“String #5 “); testList.add(“String #4 “); System.out.println(“Original list:”); printArrayList (testList); /*Standard sorting with Collections.sort()*/ System.out.println(“Sorted with Collections.sort():”); printArrayList (testList); System.out.println( “Sorted with lambda:”); testlist.sort(/*Your lambda expression to perform sorting based on the number of “*” in a string. Note: use provided count() method to get the number of stars in a string*/); printArrayList testList); The code needs to produce the following output Original list: String #2* String #3** String #1 String #5 Sorted with Collections.sort(): String #1 String #2* String #3** String #4 Sorted with lambda: String #2* String #3** String #5 String #4 String #4 String #5 string #1 Show transcribed image text In Java, it is possible to define generic methods. For instance, given example demonstrates a simple case for a method, that takes an array of any type ava generics.h Problem L Implement a generic method, that takes an array list, containing any type, and prints out the elements, similar to the example. Note, that even though it is possible to just use ArrayList or ArrayList Object to achieve seemingly similar functionality, your method needs to be generic, so that it accepts a parameter like this: ArrayList inputArrayList. Name your method printArray0 In most modern programming languages, it is possible to use lambda functions. Lambda function in this context is a function, that is defined in place where it is used. For instance, it can be used to sort a list, as shown in this examp ing-lam Collections.sort (personList, (Person pl, Person p2) > pl.firstName.compareTo (p2.firstName)) Problem 2. Based on the abovementioned concepts and solution to the problem 1, complete the following code import java.uti1.ArrayList; import java.util.Collections; public class TemplateMethodExampleMain public static int count (String text, String find) count -0, length int index = 0, while( (index find. length(); index))–1 ) text . index0f(find, {
index length; count++; return count; // Your implementation of a generic printArray) method public static void main(String args]) ArrayList
Expert Answer
Answer to In Java, it is possible to define generic methods. For instance, given example demonstrates a simple case for a method, … . . .
OR

