Classroom Assignment <2>: Demonstrating Set Interface in Java
Learning Objective:
To gain a clear understanding of Set Interface and its implementation classes in Java and identifying and printing only
unique characters in a given string.
Best Case: 15 minutes
Average Case: 20 minutes
Assignment Details:
- Writing a Java program that takes a string as input and prints only the unique characters from that String using
the Set interface and its implementation class.
- Given the String companyName = "google"`, the program should print: "gole"
Assignment Requirements:
- You are provided with a string variable: companyName = "google"
- Create a Set to store unique characters.
- Iterate through each character in the companyName string.
- Add each character into the Set.
- Print the unique characters from the string.
Hints to Solve:
- Initialize a Set of type Character to store unique characters.
- Loop through each character in the input string.
- Use appropriate method to add characters to the Set.
- To get the required output use the correct implementation class.
Reference Links:
Set in Java - Oracle Docs
Expected Outcome:
Upon completion, you should be able to:
- Grasp the fundamental concepts and methods associated with the Set Interface in Java.
- Understand how to effectively filter and process data to extract unique elements using Java Sets.