Question: Here are some JAVA Problems - - For each of the following exercises provide a solution that uses methods of the Stream interface. 1 .

Here are some JAVA Problems
--For each of the following exercises provide a solution that uses methods of
the Stream interface.
1.
Write a static method sumOdd that given a List of integers computes the sum of the
values that are odd.
2
Implement a generic record class ImmutablePair. Then, write a static
method someCalculation (not in ImmutablePair) that given a List
lst returns an object of ImmutablePair class. The first element of the
pair is the number of elements of lst in the range [0.2, Math.PI], and
the second element is the average of the values of lst in the range [10,100].
3
Write a static method repl that given a List xs of Object and a integer n returns an
arraylist containing the elements of xs replicated n times in any order.
Hint: consider the flatMap method of Stream.
4
Write a function titlecase that given a list of strings converts it to titlecase by
uppercasing the letters of every word that starts with an a.
5
Write a static method replaceWord that given the name of a text file (String
fileName), a word (String word) and a replacement (String repl), prints the content
of fileName where each occurrence of word is replaced with repl. Note that the
structure, i.e. lines, of fileName must be preserved. Test your method with the
file people.csv, replacing for example true with false.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!