To create nested index in MongoDB, you can use createIndex() or ensureIndex(). The syntax is as follows −db.yourCollectionName.createIndex({"yourOuterFieldName.yourInnerFieldName.yourSecondInnerFieldName": 1});To understand the syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.nestedIndexDemo.insertOne( ... { ... ... "CustomerId":101, ... "CustomerDetails": ... { ... "CustomerListDetails": ... { ... "CustomerName":"Larry", ... "CustomerProjectName": "Project-1", ... Read More
A reference variable is an alias, that is, another name for an already existing variable. Once a reference is initialized with a variable, either the variable name or the reference name may be used to refer to the variable.References vs PointersReferences are often confused with pointers but three major differences between references and pointers are −You cannot have NULL references. You must always be able to assume that a reference is connected to a legitimate piece of storage.Once a reference is initialized to an object, it cannot be changed to refer to another object. Pointers can be pointed to another ... Read More
This example demonstrate about how to get clicked item and its position in RecyclerViewStep 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 recycerview.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.annotation.TargetApi; import android.os.Build; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class ... Read More
A bipartite graph is a graph in which if the graph coloring is possible using two colors i.e.; vertices in a set are colored with the same color. This is a C++ program to Check whether a graph bipartite or not using DFS.AlgorithmBegin 1. An array color[] is used to stores 0 or 1 for every node which denotes opposite colors. 2. Call function DFS from any node. 3. If the node w has not been visited previously, then assign ! color[v] to color[w] and call DFS again to visit nodes connected to w. ... Read More
In this program we need to find the Edge Connectivity of a Graph. An Edge Connectivity of a Graph of a graph means it is a bridge, removing it graph will be disconnected. Number of connected components increases with the removing of bridge in a disconnected undirected graph.Functions and pseudocodeBegin Function connections() is a recursive function to find out the connections: A) Mark the current node un visited. B) Initialize time and low value C) Go through all vertices adjacent to this D) Check if the subtree rooted with x has a connection to one ... Read More
The value of a duration in the form of a number of minutes can be obtained using the method toMinutes() in the Duration class in Java. This method does not require any parameters and it returns the duration in the form of a number of minutes.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class GFG { public static void main(String[] args) { Duration d = Duration.ofDays(1); System.out.println("The duration is: " + d); System.out.println("Number of ... Read More
Use the contains() method to search a value in JavaTuples Pair class.Let us first see what we need to work with JavaTuples. To work with Pair class in JavaTuples, you need to import the following package −import org.javatuples.Pair;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Pair Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Pair; public class Demo { public static void main(String[] args) { Pair ... Read More
To specify exact order with where id IN, you need to use find_in_set() function.The syntax is as followsSELECT *FROM yourTableName WHERE yourColumnName IN (yourValue1, yourValue2, yourValue3, ....N) ORDER BY FIND_IN_SET(yourColumnName , ‘yourValue1, yourValue2, yourValue3, ....N’');Let us first create a tablemysql> create table FindInSetDemo - > ( - > Id int, - > Name varchar(20), - > Age int - > ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into FindInSetDemo values(10, 'John', 23); Query OK, 1 row affected (0.20 sec) mysql> insert ... Read More
A hit counter tells you about the number of visits on a particular page of your web site. Usually, you attach a hit counter with your index.jsp page assuming people first land on your home page.To implement a hit counter you can make use of the Application Implicit object and associated methods getAttribute() and setAttribute().This object is a representation of the JSP page through its entire lifecycle. This object is created when the JSP page is initialized and will be removed when the JSP page is removed by the jspDestroy() method.Following is the syntax to set a variable at the ... Read More
An immutable copy of a MonthDay with the day of month altered as required is done using the method withDayOfMonth() in the MonthDay class in Java. This method requires a single parameter i.e. the day of month that is to be set in the MonthDay and it returns the MonthDay with the day of month altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { MonthDay md1 = MonthDay.parse("--02-22"); System.out.println("The MonthDay ... Read More