Question

Please teach me how to use function interface by java ● Write a functional interface StringOperator...

Please teach me how to use function interface by java

● Write a functional interface StringOperator with the method performOperation
that takes two references to String objects as parameters.
● In a driver program, use lambda expressions to create two different objects that
implement the StringOperator interface.
○ One of them concatenates the two Strings, returning the new String
○ One of them sets the first String to all uppercase and the second String to all
lowercase and then concatenates them, returning the new String
● Test using both objects in a driver program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//In case of any, queries, please revert back
public class Solution
{
   //we first declare an interface
   interface StringOperator
   {    //now we define operations or methods
  
       void performOperation(String message1,String message2);
   }

   public static void main(String args[])
   {
   //syntax for writing lambda functions
       StringOperator concat = (message1,message2) ->System.out.println(message1
                                               + message2);
   StringOperator concatModified=(message1,message2) ->System.out.println(message1.toUpperCase()
                                               + message2.toLowerCase());
      
concatModified.performOperation("Hello","World");
   concat.performOperation("Hello","World");
  
   }
}

Add a comment
Know the answer?
Add Answer to:
Please teach me how to use function interface by java ● Write a functional interface StringOperator...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a java program that creates two interfaces named test1 and test2. In interface test1 the...

    Write a java program that creates two interfaces named test1 and test2. In interface test1 the member function is square. In interface test2 the member function is cube. Implement these two interfaces in "Arithmetic" class. Create one new class called ToTestInt in this class use the object of arithmetic class.

  • language is java Restrictions: You are not allowed to use anything from the String, StringBuilder, or...

    language is java Restrictions: You are not allowed to use anything from the String, StringBuilder, or Wrapper classes. In general, you may not use anything from any other Java classes, unless otherwise specified. You are not allowed to use String literals in your code ("this is a string literal"). You are not allowed to use String objects in your code. The methods must be implemented by manipulating the data field array, The CSString Class: NOTE: Pay very careful attention to...

  • P9.17 (For Java, and can you please explain as well.) Declare an interface Filter as follows:...

    P9.17 (For Java, and can you please explain as well.) Declare an interface Filter as follows: public interface Filter { boolean accept(Object x); } Write a method: public static ArrayList collectAll(ArrayList objects, Filter f) that returns all objects in the objects list that are accepted by the given filter. Provide a class ShortWordFilter whose filter method accepts all strings of length < 5. Then write a program that asks the user for input and output textfile names, reads all words...

  • Prompt the user to enter two character strings. The program will then create a new string...

    Prompt the user to enter two character strings. The program will then create a new string which has the string that appears second, alphabetically, appended to the end of the string that shows up first alphabetically. Use a dash (-') to separate the two strings. You must implement the function string appendStrings(string, string), where the return value is the combined string. Display the newly created string. Your program must be able to handle both uppercase and lowercase characters. You are...

  • Java program. Code the following interfaces, implement them, and use the interface as a parameter, respectively:...

    Java program. Code the following interfaces, implement them, and use the interface as a parameter, respectively: a. An interface called Printable with a void print() method. b. An interface called EmployeeType with FACULTY and CLASSIFIED integer data. The value of FACULTY is 1 and CLASSIFIED is 2. a. A class called Employee to implement the two interfaces. Its constructor will initialize three instance data as name, employeeType, and salary. Implementation of method print() will display name, employeeType, and salary; salary...

  • Please write a Java interface for an integer stack (should have the methods push, pop, toString)....

    Please write a Java interface for an integer stack (should have the methods push, pop, toString). Then implement this interface using one of our linked list nodes. Then please write an interface for an integer queue ( should have methods enqueue, dequeue, and toString). Then implement this interface using one of our linked list objects. Please see chapter 3 in the text for a definition of a stack. Please write a program that asks the user for how many numbers...

  • s1 = 'Practice How to Use String Object' Write a python statement that splits the string,...

    s1 = 'Practice How to Use String Object' Write a python statement that splits the string, creating the following list: ['Practice', 'How', 'to', 'Use', 'String', 'Object'] 2. Assume reply references a string. The following if statement determines whether reply is equal to ‘Y’ or ‘y’: reply = input("Y or y to continue: ") if reply == "Y" and reply == "y":    print("Y --- <uppercase> has been selected. ") else:    print("y --- <lowercase> has been chosen. ") print("… continue...

  • Can some please help me to answer these two questions. Write a program in Java create...

    Can some please help me to answer these two questions. Write a program in Java create a class diagram fragment with two classes: User and Patient. Patient is a sub-class of User. User has a method getName(), which is both over-loaded and over-ridden in the subclass In Java write an abstract class called User. User has one abstract method called authenticate, which takes two string parameters. Write a concrete sub-class of User called Administrator with an implementation of the authenticate...

  • JAVA Create a simple Graphical User Interface (GUI) in java with the following requirements:  The...

    JAVA Create a simple Graphical User Interface (GUI) in java with the following requirements:  The interface components will appear centered in the interface, and in two rows. o Row one will have a Label that reads “Please enter a valid integer:” and a Text Field to take in the integer from the user. o Row two will have a Button that when pressed converts the integer to binary  The conversion will be completed using recursion – A separate...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT