Samual Sam has Published 2491 Articles

Create a directory in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

700 Views

A directory can be created with the required abstract path name using the method java.io.File.mkdir(). This method requires no parameters and it returns true on the success of the directory creation or false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {   ... Read More

Java Program to check if a given value exists in a HashMap

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

3K+ Views

Use the containsValue() method to check if a given value exists or not in a HashMap.First, let us create a HashMap and add some elements −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 ... Read More

Remove a value from TreeMap in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

642 Views

Use the remove() method to remove a value from TreeMap.Create a TreeMap first and add some elements −TreeMap m = new TreeMap(); m.put(1, "PHP"); m.put(2, "jQuery"); m.put(3, "JavaScript"); m.put(4, "Ruby"); m.put(5, "Java"); m.put(6, "AngularJS"); m.put(7, "ExpressJS");Now, let’s say you need to remove a value with key 5. For that, use ... Read More

What is pipelining?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

8K+ Views

In computer networking, pipelining is the method of sending multiple data units without waiting for an acknowledgment for the first frame sent. Pipelining ensures better utilization of network resources and also increases the speed of delivery, particularly in situations where a large number of data units make up a message ... Read More

Modify the value associated with a given key in Java HashMap

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

240 Views

First, create a HashMap and add elements to it −// 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));Now, to modify the value associated with a given key, use ... Read More

Java Program to delete a file or directory when the program ends

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

158 Views

A file or directory with the required abstract pathname can be deleted when the program ends i.e. after the virtual machine terminates using the method java.io.File.deleteOnExit(). This method requires no parameters and it does not return a value.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public ... Read More

Java Program to remove a key from a HashMap only if it is associated with a given value

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

93 Views

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 ... Read More

Remove a key from TreeMap in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

447 Views

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 ... Read More

Create a file and change its attribute to read-only in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

1K+ Views

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 {   ... Read More

Java Program to copy all the key-value pairs from one Map into another

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

438 Views

To copy, use the putAll() method.Let us first create two Map −First Map −HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600));Second Map −HashMap hm2 = new HashMap(); hm.put("Bag", new Integer(1100)); hm.put("Sunglasses", new Integer(2000)); hm.put("Frames", new Integer(800));Now, copy the key-value pairs from one Map to another −hm.putAll(hm2);The following ... Read More

Advertisements