Create Queue from LinkedList in Java

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

395 Views

Let us create a queue from LinkedList like this −Queuequeue = new LinkedList(); queue.add("P"); queue.add("Q"); queue.add("R"); queue.add("S"); queue.add("T"); queue.add("U"); queue.add("V");Now, use a List to display the elements of the queue −Listlist = new ArrayList(queue);Example Live Demoimport java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; public class Demo {    public static void main(String[] args) {       Queuequeue = new LinkedList();       queue.add("P");       queue.add("Q");       queue.add("R");       queue.add("S");       queue.add("T");       queue.add("U");       queue.add("V");       Listlist = new ArrayList(queue);       for (Object ... Read More

Export Specific Column Data in MySQL

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

925 Views

To export specific column data in MySQL, use OUTFILE −select yourColumnName from yourTableName into outfile 'yourLocationOfFile’;Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentFirstName varchar(20),    StudentLastName varchar(20) ); Query OK, 0 rows affected (0.54 sec)Insert records in the table using insert command −mysql> insert into DemoTable(StudentFirstName, StudentLastName) values('John', 'Doe'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable(StudentFirstName, StudentLastName) values('David', 'Miller'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(StudentFirstName, StudentLastName) values('John', 'Smith'); Query OK, 1 row affected (0.15 sec) mysql> insert into ... Read More

Create Temporary File in Specified Directory in Java

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

3K+ Views

A temporary file in the specified directory can be created using the method java.io.File.createTempFile(). This method requires three parameters i.e. the prefix to define the file name, the suffix to define the file extension and the directory in which the temporary file is to be created. It also returns the abstract path name for the temporary file created.A program that demonstrates this is given as follows −Exampleimport java.io.File; public class Demo {      public static void main(String[] args) throws Exception {       File directory = new File("C:/JavaProgram");       File file = File.createTempFile("temp", ".java", directory);   ... Read More

CharBuffer ArrayOffset Method in Java

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

106 Views

The offset of the first element of the buffer inside the buffer array is obtained using the method arrayOffset() in the class java.nio.CharBuffer. If the buffer backed by the array is read-only, then the ReadOnlyBufferException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          CharBuffer buffer = CharBuffer.allocate(5);          buffer.put('A');          buffer.put('P');          buffer.put('P');         ... Read More

Unordered Multimap Operator in C++

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

100 Views

The C++ function std::unordered_multimap::operator=() assigns new contents to the unordered_multimap by replacing old ones and modifies size if necessary.Following is the declaration for std::unordered_multimap::operator=() function form std::unordered_map() header.C++11 (Syntax)unordered_multimap& operator=(const unordered_multimap& umm);Parametersumm - Another unordered_multimap object of same type.Return ValueReturns this pointer.Example Code#include #include using namespace std; int main(void) {    unordered_multimap umm1 = {       {'a', 1},       {'b', 2},       {'c', 3},       {'d', 4},       {'e', 5},    };    unordered_multimap umm2;    umm2 = umm1;    cout

Change the Type of a Field in MongoDB

Nancy Den
Updated on 30-Jul-2019 22:30:25

2K+ Views

Let us convert string type to int for an example. Aggregation does not allow us to directly change the type of a field; therefore, you need to write a code to convert the type of a field.At first, create a collection with document. After that we will get the type of every field. The query to create a collection with document is as follows>db.changeDataType.insertOne({"StudentName":"Larry", "StudentAge":23, "StudentZipCode":" 10001", "isProgrammer":false}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6ed4976fd07954a4890694") }Display all documents from a collection with the help of find() method. The query is as follows:> db.changeDataType.find().pretty();The following is the output:{   ... Read More

Delete Session Data in JSP

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

4K+ Views

When you are done with a user's session data, you have several options −Remove a particular attribute − You can call the public void removeAttribute(String name) method to delete the value associated with the particular key.Delete the whole session − You can call the public void invalidate() method to discard an entire session.Setting Session timeout − You can call the public void setMaxInactiveInterval(int interval) method to set the timeout for a session individually.Log the user out − The servers that support servlets 2.4, you can call logout to log the client out of the Web server and invalidate all sessions ... Read More

Get Yesterday Records from Timestamp in Android SQLite

Nitya Raut
Updated on 30-Jul-2019 22:30:25

243 Views

Before getting into example, we should know what sqlite data base in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrate about How to get yesterday records from timestamp in Android sqlite.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required ... Read More

DoubleStream max() Method in Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

268 Views

The max() method of the DoubleStream class returns an OptionalDouble describing the maximum element of this stream, or an empty OptionalDouble if this stream is empty.The syntax is as follows.OptionalDouble max()Here, OptionalDouble is a container object which may or may not contain a double value.To use the DoubleStream class in Java, import the following package.import java.util.stream.DoubleStream;Create a DoubleStream and add some elements.DoubleStream doubleStream = DoubleStream.of(67.9, 89.9, 10.5, 95.8, 49.6);Now, get the maximum element from the stream.OptionalDouble res = doubleStream.max();The following is an example to implement DoubleStream max() method in Java.Example Live Demoimport java.util.OptionalDouble; import java.util.stream.DoubleStream; public class Demo {    public ... Read More

Get Hour from LocalDateTime in Java

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

153 Views

The hour of the day for a particular LocalDateTime can be obtained using the getHour() method in the LocalDateTime class in Java. This method requires no parameters and it returns the hour of the day which can range from 0 to 23.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T15:28:35");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The hour is: " + ldt.getHour());    } }OutputThe LocalDateTime is: 2019-02-18T15:28:35 The hour is: 15Now let ... Read More

Advertisements