Use the remove() method to remove a key only if it is associated with a given value.Let’s say the following is our HashMap −// Create a hash map HashMap hm = new HashMap(); // Put elements to the map hm.put("Bag", new Integer(1100)); hm.put("Sunglasses", new Integer(2000)); hm.put("Frames", new Integer(800)); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600));Here, we are removing a key “Belt” only if it is associated with the given value 600 −hm.remove("Belt", 600);The following is an example to remove a key only if it is associated with a given value −Example Live Demoimport java.util.*; public class Demo { public static void ... Read More
Yes. We can find the word dictionary in a dictionary. When I referred to the Oxford Dictionary, I came across the following meaning.Dictionary: A book or electronic resource that lists the words of a language (typically in alphabetical order) and gives their meaning, or gives the equivalent words in a different language, often also providing information about pronunciation, origin, and usage.Usage:-- ‘I'll look up 'love' in the dictionary’-- ‘the website gives access to an online dictionary’
Cast DECIMAL to INT with the help of FLOOR() function. The syntax is as follows −SELECT FLOOR(yourColumnName) from yourTableName where condition;Let us first create a table. The following is the query to create a table.mysql> create table DecimalToIntDemo -> ( -> Amount DECIMAL(3, 1) -> ); Query OK, 0 rows affected (0.88 sec)Now you can insert records into the table with the help of insert command. The query is as follows −mysql> insert into DecimalToIntDemo values(12.5); Query OK, 1 row affected (0.23 sec) mysql> insert into DecimalToIntDemo values(50.4); Query OK, 1 ... Read More
Use Iterator to iterate through the values of HashMap −HashMap hm = new HashMap(); // Put elements to the map hm.put("Bag", new Integer(1100)); hm.put("Sunglasses", new Integer(2000)); hm.put("Frames", new Integer(800)); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600));Now, use Iterator to display each and every value and key −// Get an iterator Iterator i = set.iterator(); // Display elements while(i.hasNext()) { Map.Entry me = (Map.Entry)i.next(); System.out.print(me.getKey() + ": "); System.out.println(me.getValue()); }The following is an example to iterate through the values of HashMap −Example Live Demoimport java.util.*; public class Demo { public static ... Read More
Sanskrit is the Holy and Divine language of India, written in Devanagari script which is also known for its clarity and beauty. Sanskrit belongs to the Indo-European languages family. The meaning of the word "Sanskrit" is refined, decorated and produced in perfect form. This is the oldest language ever attested on Earth.Covers A Larger PrecinctThough not for all the languages, Sanskrit is surely the mother of many languages, especially languages spoken in Northern India. Even many words from Dravidian languages are derived from Sanskrit. Almost all of the ancient kinds of literature such as the Vedas, Upanishads, Epics, Shastras, Puranas ... Read More
Use the remove() method to remove a key from TreeMap.Let us first create a TreeMap and add some elements −TreeMap m = new TreeMap(); m.put(1, "India"); m.put(2, "US"); m.put(3, "Australia"); m.put(4, "Netherlands"); m.put(5, "Canada");Let us remove a key now. Here, we are removing key 3 now −m.remove(3)The following is an example to remove a key from TreeMap −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]) { TreeMap m = new TreeMap(); m.put(1, "India"); m.put(2, "US"); m.put(3, "Australia"); m.put(4, "Netherlands"); ... Read More
The attribute of a file can be changed to read-only by using the method java.io.File.setReadOnly(). This method requires no parameters and it returns true if the file is set to read-only and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo { public static void main(String[] args) { boolean flag; try { File file = new File("demo1.txt"); file.createNewFile(); flag = file.setReadOnly(); System.out.println("File is read-only?: " + flag); ... Read More
It won't be surprising for you to hear that mobile phone usage has been increasing day by day. With the launch of modern smartphones hitting the market, much of the population now expect to be able to do many everyday tasks through their mobile phones. As more and more people are using mobile phones over desktop it is clear that the mobile phone is taking over desktops for internet surfing.The fundamental thing for a website is that it should be mobile friendly; it should be designed in such a way that it is equally compatible with mobile phones as well ... Read More
An LinkedList can be cleared in Java using the method java.util.LinkedList.clear(). This method removes all the elements in the LinkedList. There are no parameters required by the LinkedList.clear() method and it returns no value.A program that demonstrates this is given as follows.Example Live Demoimport java.util.LinkedList; public class Demo { public static void main(String[] args) { LinkedList l = new LinkedList(); l.add("Orange"); l.add("Apple"); l.add("Peach"); l.add("Guava"); ... Read More
Use the remove() method to remove a key from a TreeMap only if it is associated with a given value. Let us first create a TreeMap and add some elements −TreeMap m = new TreeMap(); m.put(1, "India"); m.put(2, "US"); m.put(3, "Australia"); m.put(4, "Netherlands"); m.put(5, "Canada");To remove a key, set the key and the associated value here. If the associate value exists, then the key will get removed −m.remove(3, "Australia")The following is an example to remove a key from a TreeMap only if it is associated with a given value −Example Live Demoimport java.util.*; public class Demo { public static void ... Read More