Period minusMonths Method in Java

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

148 Views

An immutable copy of the Period object where some months are subtracted from it can be obtained using the minusMonths() method in the Period class in Java. This method requires a single parameter i.e. the number of months to be subtracted and it returns the Period object with the subtracted months.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y7M15D";       Period p1 = Period.parse(period);       System.out.println("The Period is: " + p1);       Period p2 ... Read More

Example Data Link Protocols

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

16K+ Views

The data link protocols operate in the data link layer of the Open System Interconnections (OSI) model, just above the physical layer.The services provided by the data link protocols may be any of the following −Framing − The stream of bits from the physical layer are divided into data frames whose size ranges from a few hundred to a few thousand bytes. These frames are distributed to different systems, by adding a header to the frame containing the address of the sender and the receiver.Flow Control − Through flow control techniques, data is transmitted in such a way so that ... Read More

Create Key-Value Tuple from a List Collection in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

151 Views

To create KeyValue tuple from List collection, use the fromCollection() method. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following package:import org.javatuples.KeyValue;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples:Steps: How to run JavaTuples program in EclipseThe following is an example to create KeyValue Tuple from List ... Read More

Renaming Column Name in a MongoDB Collection

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

746 Views

To rename column name in a collection, you can use $rename operator. Following is the syntaxdb.yourCollectionName.update({}, {$rename: {'yourOldColumName': 'yourNewColumnName'}}, false, true);Let us first create a collection with documents:> db.renamingColumnNameDemo.insertOne({"StudentName":"Larry", "Age":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9ee2c6d628fa4220163b9a") } > db.renamingColumnNameDemo.insertOne({"StudentName":"Sam", "Age":26}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9ee2d0d628fa4220163b9b") } > db.renamingColumnNameDemo.insertOne({"StudentName":"Robert", "Age":27}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9ee2dbd628fa4220163b9c") }Following is the query to display all documents from a collection with the help of find() method> db.renamingColumnNameDemo.find().pretty();This will produce the following output{    "_id" : ObjectId("5c9ee2c6d628fa4220163b9a"),    "StudentName" : "Larry",    "Age" : 23 ... Read More

Select First Element of a Comma-Separated List in MySQL

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

1K+ Views

To select first element of a comma-separated list, you can use SUBSTRING_INDEX(). Let us first create a table:mysql> create table DemoTable (    CSV_Value varchar(200) ); Query OK, 0 rows affected (0.81 sec)Following is the query to insert some records in the table using insert command. We have inserted records in the form of comma-separated integer list:mysql> insert into DemoTable values('10, 20, 50, 80'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('100, 21, 51, 43'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('1, 56, 103, 1090'); Query OK, 1 row affected (0.26 ... Read More

AbstractSequentialList in Java

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

138 Views

The Java Collection Framework contains the AbstractSequentialList class. This class is used to create and implement an unmodifiable list. Also this class implements the Collection interface and the AbstractCollection class.A program that demonstrates this is given as follows −Example Live Demoimport java.util.*; public class Demo {    public static void main(String[] args) {       AbstractSequentialList list = new LinkedList();       list.add("John");       list.add("Martha");       list.add("Sally");       list.add("Susan");       list.add("Harry");       System.out.println("The elements are: " + list);    } }The output of the above program is as follows ... Read More

CharBuffer.wrap() Method in Java

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

289 Views

A character array can be wrapped into a buffer using the method wrap() in the class java.nio.CharBuffer. This method requires a single parameter i.e. the char array to be wrapped into a buffer and it returns the new buffer created. If the returned buffer is modified, then the contents of the array are also similarly modified and vice versa.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) { try { ... Read More

C++ Program That Will Fill Whole Memory

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

340 Views

In this article we will see how to fill the whole memory by writing a simple C++ program. Here the logic is very simple. We shall create new integer variables by using the dynamic memory allocation. If we create some variables again and again, it will fill the entire primary memory.In C++ to dynamically allocate a memory space we can use the new keyword.The basic syntax of the new operator is like below.pointer_var = new data_typeTo deallocate the memory space, we can use the delete keyword. The syntax isdelete pointer_varNote After running this program it may slow down the performance ... Read More

Add New Field to Every Document in a MongoDB Collection

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

2K+ Views

To add new field to every document in a MongoDB collection, you can use $set operator. The syntax is as follows:db.yourCollectionName.update({}, { $set: {"yourFieldName": yourValue} }, false, true);To understand the above syntax, let us create a collection with some documents. The query to create a collection with documents is as follows:>db.addNewFieldToEveryDocument.insertOne({"StudentName":"John", "StudentAddress":"US "}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6efc0b6fd07954a48906ae") } >db.addNewFieldToEveryDocument.insertOne({"StudentName":"David", "StudentAddress":"U K"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6efc0b6fd07954a48906af") } >db.addNewFieldToEveryDocument.insertOne({"StudentName":"Carol", "StudentAddress":"U K"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6efc0b6fd07954a48906b0") } >db.addNewFieldToEveryDocument.insertOne({"StudentName":"Bob", "StudentAddress":"US" }); {    "acknowledged" : true,    "insertedId" : ... Read More

Enable Vertical Scroll Bar for Android WebView

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

3K+ Views

This example demonstrate about How to set default text encoded for android webview.Step 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. In the above code, we have taken web view to show facebook.com.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.app.ProgressDialog; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.webkit.CookieManager; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.EditText; public class MainActivity extends ... Read More

Advertisements