Karthikeya Boyini has Published 2193 Articles

Convert a Set into a List in Java

karthikeya Boyini

karthikeya Boyini

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

273 Views

First, create a Set and add elements −Set s = new HashSet(); s.add("P"); s.add(new Date()); s.add(new Long(898999)); s.add("Q"); s.add("R"); s.add(new Integer(1));Convert the above Set to a List −List l = new ArrayList(s);The following is an example to convert a set into a list in Java −Example Live Demoimport java.util.ArrayList; import java.util.Date; ... Read More

Find maximum element of HashSet in Java

karthikeya Boyini

karthikeya Boyini

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

4K+ Views

To get the maximum element of HashSet, use the Collections.max() method.Declare the HashSet −Set hs = new HashSet();Now let us add the elements −hs.add(29); hs.add(879); hs.add(88); hs.add(788); hs.add(456);Let us now get the maximum element −Object obj = Collections.max(hs);The following is an example to find maximum element of HashSet −Example Live Demoimport ... Read More

Fetch key-valuepair from Java LinkedHashSet

karthikeya Boyini

karthikeya Boyini

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

344 Views

To fetch LinkedHashSet key-value pair in Java, use the entrySet() method.Let us first create LinkedHashSet and add some elements −LinkedHashMap l = new LinkedHashMap(); l.put("1", "Jack"); l.put("2", "Tom"); l.put("3", "Jimmy"); l.put("4", "Morgan"); l.put("5", "Tim"); l.put("6", "Brad");Now, fetch a key-value pair −l.entrySet()The following is an example to fetch key-value pair from ... Read More

Java Program to check if a particular key exists in TreeMap

karthikeya Boyini

karthikeya Boyini

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

182 Views

To check if a particular key exists in TreeMap, use the containsKey() method.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 we need to check that key 5 exists or ... Read More

Check if the File object refers to an absolute pathname in Java

karthikeya Boyini

karthikeya Boyini

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

526 Views

The method java.io.File.isAbsolute() is used to check if the file object refers to an absolute pathname. This method returns true if the abstract path name is absolute and false if the abstract path name is not absolute.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class ... Read More

Get the String representation of the current File object in Java

karthikeya Boyini

karthikeya Boyini

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

222 Views

The string representation of the current file object can be obtained using the method java.io.File.toString(). This method returns the abstract path name in the string form.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 Head Map from TreeMap in Java

karthikeya Boyini

karthikeya Boyini

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

222 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

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

Check whether the file is hidden or not in Java

karthikeya Boyini

karthikeya Boyini

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

752 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

804 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

Advertisements