Karthikeya Boyini has Published 2383 Articles

Get Head Map from TreeMap in Java

karthikeya Boyini

karthikeya Boyini

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

149 Views

Use the headMap() method in Java to get ahead map. It returns a view of the portion of this map whose keys are less than or equal to.Let’s say you need to get the portion of the map above the set map (and not inclusive of it). For that, use ... Read More

Check whether a file is a directory in Java

karthikeya Boyini

karthikeya Boyini

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

4K+ Views

The method java.io.File.isDirectory() checks whether a file with the specified abstract path name is a directory or not. This method returns true if the file specified by the abstract path name is a directory and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class ... Read More

Add elements at beginning and end of LinkedList in Java

karthikeya Boyini

karthikeya Boyini

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

2K+ Views

Elements can be added at the beginning of a LinkedList by using the method java.util.LinkedList.addFirst(). This method has a single argument i.e. the element that is to be added at the beginning of the LinkedList.Elements can be added at the end of a LinkedList by using the method java.util.LinkedList.addLast(). This ... Read More

Check whether the file is hidden or not in Java

karthikeya Boyini

karthikeya Boyini

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

501 Views

The method java.io.File.isHidden() is used to check whether the given file specified by the abstract path name is a hidden file in Java. This method returns true if the file specified by the abstract path name is hidden and false otherwise.A program that demonstrates this is given as follows −Example Live ... Read More

Check whether we can write to a file in Java

karthikeya Boyini

karthikeya Boyini

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

596 Views

The method java.io.File.canWrite() is used to check whether the file can be written to in Java. This method returns true if the file specified by the abstract path name can be written to by an application and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; ... Read More

Append all elements of other Collection to ArrayList in Java

karthikeya Boyini

karthikeya Boyini

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

338 Views

The elements of a Collection can be appended at the end of the ArrayList using the method java.util.ArrayList.addAll(). This method takes a single parameter i.e. the Collection whose elements are added to the ArrayList.A program that demonstrates this is given as follows −Example Live Demoimport java.util.ArrayList; import java.util.Vector; public class Demo ... Read More

Retrieve the last element from a LinkedList in Java

karthikeya Boyini

karthikeya Boyini

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

2K+ Views

The last element of a Linked List can be retrieved using the method java.util.LinkedList.getLast() respectively. This method does not require any parameters and it returns the last element of the LinkedList.A program that demonstrates this is given as follows −Example Live Demoimport java.util.LinkedList; public class Demo {    public static void ... Read More

Java Program to get the File object with the absolute path for the directory or file

karthikeya Boyini

karthikeya Boyini

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

998 Views

The method java.io.File.getAbsoluteFile() is used to get the File object with the absolute path for the directory or file. 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) {       File ... Read More

IdentityHashMap size() method in Java

karthikeya Boyini

karthikeya Boyini

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

63 Views

The size() method is used in IdentityHashMap to get the size of the map i.e. the count of elements.Let us first create IdentityHashMap and add some elements −Map m = new IdentityHashMap(); m.put("1", 100); m.put("2", 200); m.put("3", 300); m.put("4", 150); m.put("5", 110); m.put("6", 50);Now, get the size −m.size()The following is ... Read More

Retrieve TreeMap size in Java

karthikeya Boyini

karthikeya Boyini

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

131 Views

Get the TreeMap size using the size() method.First, create a TreeMap and add elements to it −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");Count the number of elements in the above TreeMap or get the size using the size() ... Read More

Advertisements