Write a java program to add 4 different printers in a hashset. What will happen when you add duplicate elements?
Set is a collection which doesn't contains duplicate elements.
Java code:
import java.util.HashSet;
public class TestClass{
public static void main(String[]args){
//HashSet
HashSet<String> printerSet = new HashSet<String>();
//adding 4 printers to HashSet
printerSet.add("Laser printers");
printerSet.add("Line printers");
printerSet.add("Daisy-wheel printers");
printerSet.add("Drum printer");
//displaying the output
System.out.println("Before adding duplicate element:");
System.out.println("--------------------------------");
for(String printers: printerSet){
System.out.println(printers);
}
//Now adding duplicate element to the printer
System.out.println("\nAdding duplicate element:");
printerSet.add("Line printers");
//again displaying the output
System.out.println("\nAfter adding duplicate element:");
System.out.println("--------------------------------");
for(String printers: printerSet){
System.out.println(printers);
}
}
}
Output:

Write a java program to add 4 different printers in a hashset. What will happen when...
1. Write a java program to find the sum of the elements on the diagonal of a matrix. 2. Write a java program to add two matrices. 3. Write a java program to find a given value in a matrix. 4. Write a java program to multiply two matrices. 5. Write a java program to find the transpose of a matrix.
Write a Java program to remove the duplicate elements of a given array and return the new length of the array. Sample array: [20, 20, 32, 76, 30, 40, 50, 50, 52] After removing the duplicate elements the program should return 6 as the new length of the array. Out put Original array length: 9 Array elements are: 20 20 32 76 30 40 50 50 52 The new length of the array is: 7
Write a java program to remove duplicate elements from an array. Do not use Java library utilities or 3rd party tools to solve this problem. You need to use the “for loop” and manage the index as you traverse thru the array [i ] while looking for duplicates. For example: Example 1 --------------------- Original Array: 105 123 -921 -1 123 8 8 8 -921 Array with unique values: 105 123 -921 -1 8 Example 2 --------------------------- Original Array: 10 22...
Write a java program that displays the sum of the elements in Column x of a 2D array (careful with rows of different lengths!)
Write a Java program to find the duplicate values of an array of integer values. import java.util.Arrays; public class ex7DuplicateValue { public static void main(String[] args) { int[] my_array = {1, 2, 3, 3, 4, 5, 6, 2}; } } //Duplicate Element : 2 //Duplicate Element : 3
I need help with my Java code. A user enters a sentence and the program will tell you what words were duplicated and how many times. If the same word is in the sentence twice, but one is capitalized, it will not count it as a duplicate. How can I make the program read the same word as the same word, even if one is capitalized and the other is not? For example, "the" and "The" should be counted as...
Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs six numbers [Keep the numbers in an array]. The numbers must be between 20 and 200, inclusive. If the number is not between 20 and 200, ask for another input. When a number is entered, display the number only if it is not a duplicate of a number already entered. If it is a duplicate of a number already entered, display a message that...
Write a program in Java using MVC (Model, View, Controller) architecture using either HashSet or TreeSet implementation where users can able to getItem, searchItem, removeItem, and addItem to the list.
Q1. Write a program in Java a. Create 2 separate arrays, of user defined values, of same size b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....
please write code in java language and do not add any break,
continue or goto statements
Write a program with a graphical interface that allows the user to convert an amount of money between U.S. dollars (USD), euros (EUR), and British pounds (GBP). The user interface should have the following elements: a text box to enter the amount to be converted, two combo boxes to allow the user to select the currencies, a button to make the conversion, and a...