Samual Sam has Published 2310 Articles

Adding elements in the middle of an ArrayList in Java

Samual Sam

Samual Sam

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

5K+ Views

Elements can be added in the middle of an ArrayList by using the java.util.ArrayList.add() method. This method has two parameters i.e. the index at which to insert the element in the ArrayList and the element itself. If there is an element already present at the index specified by ArrayList.add() then ... Read More

Get the absolute path for the directory or file in Java

Samual Sam

Samual Sam

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

3K+ Views

The method java.io.File.getAbsolutePath() is used to obtain the absolute path name of a file or directory in the form of a string. This method requires no parameters.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {    public static void main(String[] args) {   ... Read More

Get the count of NavigableMap in Java

Samual Sam

Samual Sam

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

131 Views

To get the count of NavigableMap in Java, use the size() method.Let us first create NavigableMap and add elements −NavigableMap n = new TreeMap(); n.put(5, "Tom"); n.put(9, "John"); n.put(14, "Jamie"); n.put(1, "Tim"); n.put(4, "Jackie");Now, get the count −n.size()The following is an example to implement the size() method to get the ... Read More

Display the length of current file in Java

Samual Sam

Samual Sam

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

123 Views

The length of the current file specified by the abstract path name can be displayed using the method java.io.File.length(). The method returns the file length in bytes and does not require any parameters.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {    public ... Read More

Create a directory in Java

Samual Sam

Samual Sam

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

848 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

839 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

10K+ 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

299 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

223 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

Advertisements