Samual Sam has Published 2491 Articles

Get lowest key stored in Java TreeMap

Samual Sam

Samual Sam

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

1K+ Views

Use the firstKey() method to get the lowest key stored in TreeMap.Let us first set the TreeMap and add some 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");Now get the lowest key −m.firstKey()The following is an ... Read More

Check whether the given file is an existing file in Java

Samual Sam

Samual Sam

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

97 Views

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

Delete first and last element from a LinkedList in Java

Samual Sam

Samual Sam

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

313 Views

The first element can be deleted from a LinkedList by using the method java.util.LinkedList.removeFirst(). This method does not have any parameters and it returns the first element of the LinkedList.The last element can be deleted from a LinkedList by using the method java.util.LinkedList.removeLast(). This method does not have any parameters ... Read More

Check whether the file can be read in Java

Samual Sam

Samual Sam

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

436 Views

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

Adding elements in the middle of an ArrayList in Java

Samual Sam

Samual Sam

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

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

88 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

Java Program to get highest key stored in TreeMap

Samual Sam

Samual Sam

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

1K+ Views

Use the lastKey() method to get the highest key stored in TreeMap.Let us first set the TreeMap and add some 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");Now get the highest key −m.lastKey()The following is an ... Read More

Display the length of current file in Java

Samual Sam

Samual Sam

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

75 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

Add elements to HashSet in Java

Samual Sam

Samual Sam

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

241 Views

First, create a HashSet −HashSet hs = new HashSet();Now, add some elements using the add() method. Set the elements as a parameter. Here, we have set string −hs.add("B"); hs.add("A"); hs.add("D"); hs.add("E"); hs.add("C"); hs.add("F"); hs.add("K"); hs.add("M");The following is an example to add elements to a HashSet −Example Live Demoimport java.util.*; public class ... Read More

Advertisements