Let’s say the following is our HashMap −HashMapmap = new HashMap(); map.put(10, "A"); map.put(20, "B"); map.put(30, "C"); map.put(40, "D"); map.put(50, "E"); map.put(60, "F"); map.put(70, "G"); map.put(80, "H");To retrieve all the keys, iterator through each and every key-value pair −Setset = map.keySet(); Iteratori = set.iterator(); while (i.hasNext()) { Integer res = i.next(); System.out.println(res + ": " + map.get(res)); }Example Live Demoimport java.util.HashMap; import java.util.Iterator; import java.util.Set; public class Demo { public static void main(String[] args) { HashMapmap = new HashMap(); map.put(10, "A"); map.put(20, "B"); map.put(30, "C"); ... Read More
To select from a set of integers, you can use UNION. Following is the syntax −SELECT yourValue1 UNION SELECT yourValue2 UNION SELECT yourValue3 UNION SELECT yourValue4 . . . . NLet us implement the above syntax to select from a set of integers in MySQL −mysql> SELECT 1000 UNION SELECT 2000 UNION SELECT 3000 UNION SELECT 4000 UNION SELECT 5000 UNION SELECT 6000 UNION SELECT 7000;This will produce the following output −+------+ | 1000 | +------+ | 1000 | | 2000 | | 3000 | | 4000 | | 5000 | | 6000 | | 7000 | +------+ 7 rows in set (0.03 sec)
Before having a discussion regarding the demerits or merits of I/O mapped I/O and memory-mapped I/O, let us have a generic discussion regarding the difference between I/O mapped I/O and memory mapped I/O.In Memory Mapped Input Output −We allocate a memory address to an Input-Output device.Any instructions related to memory can be accessed by this Input-Output device.The Input-Output device data are also given to the Arithmetic Logical Unit.Input-Output Mapped Input Output −We give an Input-Output address to an Input-Output deviceOnly IN and OUT instructions are accessed by such devices.The ALU operations are not directly applicable to such Input-Output data.So as ... Read More
A ResultSet interface in JDBC represents the tabular data generated by SQL queries. It has a cursor which points to the current row. Initially this cursor is positioned before first row.You can move the cursor using the next() method and, you can retrieve the column values of a row using the getter methods of the ResultSet interface (getInt(), getString(), getDate() etc..).To retrieve required data from a table:Connect to the database.Create a Statement object.Execute the Statement using the executeQuery() method. To this method, pass the select query in the String format. To retrieve all the values, we use the following query:Select ... Read More
The accept() method of the DoubleStream class in Java adds an element to the stream being built.The syntax is as follows −void accept(double ele)Here, ele is the element to be inserted into the stream.To use the DoubleStream.Builder class in Java, import the following package −import java.util.stream.DoubleStream;The following is an example to implement DoubleStream.Builder() accept() method in Java −Example Live Demoimport java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream.Builder builder = DoubleStream.builder(); builder.accept(12.9); builder.accept(25.6); builder.accept(35.8); builder.accept(43.9); builder.accept(56.3); ... Read More
You can use distinct keyword to select all values from a table only once if they are repeated.The syntax is as followsselect distinct yourColumnName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows.mysql> create table displayOnlyDistinctValue -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(100), -> UserAge int -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command.The query is as follows.mysql> insert into displayOnlyDistinctValue(UserName, UserAge) values('Larry', 23); Query OK, 1 row affected ... Read More
The addAll() method of the AbstractSequentialList class inserts all the elements in the specified collection into this list at the specified position. Set the specified position as the parameter.The syntax is as follows:boolean addAll(int index, Collection
This example demonstrate about send data through wifi in android programmaticallyNeed Server and Client ProjectServerStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javapackage com.server.myapplication.server; import android.annotation.SuppressLint; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.InetAddress; ... Read More
To track the order of insertion, you can use Map.Entry() in case of a Map. Let’s say we have the following LinkedHashMap −Mapmap = new LinkedHashMap(); map.put("Jack", 0); map.put("Tim", 1); map.put("David", 2); map.put("Tom", 3); map.put("Kevin", 4); map.put("Jeff", 5);Now, loop through Map.Entry and get the order of insertion correctly with Key and Value −for (Map.Entryentry: map.entrySet()) { System.out.println(entry.getKey() + " => " + entry.getValue()); }Example Live Demoimport java.util.LinkedHashMap; import java.util.Map; public class Demo { public static void main(String[] args) { Mapmap = new LinkedHashMap(); map.put("Jack", 0); map.put("Tim", 1); ... Read More
You can use DELETE command with some condition for this since we need to keep one record and delete rest of the duplicate records.Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(40) ); Query OK, 0 rows affected (0.48 sec)Insert records in the table using insert command −mysql> insert into DemoTable(StudentName) values('John'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(StudentName) values('Carol'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(StudentName) values('Sam'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable(StudentName) ... Read More