List File System Roots in Java

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

375 Views

The method java.io.File.listRoots() is used to list the file system roots in Java. This method requires no parameters. It returns the available file system roots in the form of an array of file objects and if the file system roots cannot be determined, it returns null.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[] roots = File.listRoots();       try {          for(File r : roots) {             System.out.println(r);         ... Read More

Get the Fields in Each Constraint in MySQL

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

107 Views

Let’s say we have a database “business” with number of tables. If you want to Get the fields in each constraint, then use the below query.The below query is to get the fields in each one of those constraints −mysql> select * −> from information_schema.key_column_usage −> where constraint_schema = 'business';The following is the output −+--------------------+-------------------+--------------------------+---------------+--------------+------------------------------+--------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ | CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME          | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME                   | COLUMN_NAME | ORDINAL_POSITION  | POSITION_IN_UNIQUE_CONSTRAINT | REFERENCED_TABLE_SCHEMA | REFERENCED_TABLE_NAME | REFERENCED_COLUMN_NAME | +--------------------+-------------------+--------------------------+---------------+--------------+------------------------------+--------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ | def         ... Read More

Retrieve Set of All Values in HashMap in Java

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

269 Views

First, create a HashMap and add elements −HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); hm.put("Backpack", new Integer(1200));Now, retrieve all the values −Collection getValues = hm.values(); System.out.println("Values..."); Iterator i = getValues.iterator(); while (i.hasNext()) { System.out.println(i.next()); }The following is an example to get the set of all the values in the HashMap −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]) { // Create hash map HashMap hm = new HashMap(); ... Read More

Remove All Values from HashMap in Java

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

5K+ Views

To remove all values from HashMap, use the clear() method.First, let us create a HashMap.HashMap hm = new HashMap();Add some elements to the HashMaphm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); hm.put("Backpack", new Integer(1200));Now, remove all the elementshm.clear();The following is an example to remove all values from HashMap.Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]) { // Create hash map HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); ... Read More

Remove the First Entry of the TreeMap in Java

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

1K+ Views

To remove the first entry of the TreeMap, use the pollFirstEntry() method.Let us first create a TreeMap and add 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");Remove the first entry now −m.pollFirstEntry()The following is an example to remove the first entry of the TreeMap.Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]) { TreeMap m = new TreeMap(); m.put(1, "India"); m.put(2, "US"); ... Read More

Get Free Space of a Partition in Java

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

439 Views

The method java.io.File.getFreeSpace() is used to obtain the free space in the form of unallocated bytes for the partition specified by the required abstract path name. This method requires no parameters and it returns the unallocated bytes for the partition.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[] roots = File.listRoots();       try {          for(File r : roots) {          System.out.println(r);          System.out.println("Free space = " + r.getFreeSpace());     ... Read More

Retrieve Map Entry Elements from a HashMap in Java

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

351 Views

Create a HashMap and add elements to it −HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); hm.put("Backpack", new Integer(1200));The following is the code snippet to retrieve a set of Map.Entry elements −Set s = hm.entrySet(); Iterator iter = s.iterator(); System.out.println("Key\tValue"); while (iter.hasNext()) { Map.Entry e = (Map.Entry) iter.next(); System.out.println(e.getKey() + " " + e.getValue()); }The following is an example to retrieve a set of Map.Entry elements from a HashMap −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]) { ... Read More

Retrieve Set of All Keys in HashMap in Java

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

294 Views

First, create a HashMap and add elementsHashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); hm.put("Backpack", new Integer(1200));Now, retrieve all the keysSet keys = hm.keySet(); System.out.println("Keys..."); Iterator i = keys.iterator(); while (i.hasNext()) {    System.out.println(i.next()); }The following is an example to get the set of all key in HashMapExample Live Demoimport java.util.*; public class Demo { public static void main(String args[]) { // Create hash map HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); ... Read More

Types of Utilitarian Ethics Followed in Engineering

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

531 Views

The Utilitarian ethics was proposed by John Stuart. According to this theory, the happiness or pleasure of the greatest number of people in society is considered as the greatest good. According to this philosophy, an action is morally right if its consequences lead to the happiness of people and wrong if they lead to their unhappiness.An example of this can be the removal of the reservation system in education and government jobs, which can really benefit the talent. But this could endanger the minority rights.Following are two main types of Utilitarianism.Act UtilitarianismRule Utilitarianism.Act UtilitarianismThe Act utilitarianism focuses on each situation ... Read More

Get First Key from NavigableMap in Java

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

183 Views

To display the first key from NavigableMap in Java, use the firstKey() method.Let us first create NavigableMap −NavigableMap n = new TreeMap(); n.put("A", 498); n.put("B", 389); n.put("C", 868); n.put("D", 988); n.put("E", 686); n.put("F", 888); n.put("G", 999); n.put("H", 444); n.put("I", 555); n.put("J", 666);Get the first key now −n.firstKey()The following is an example to get the first key from NavigableMap −Example Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { NavigableMap n = new TreeMap(); n.put("A", 498); n.put("B", ... Read More

Advertisements