How to clear Singleton instance in android?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25
Before getting into the example, we should know what singleton design pattern is. A singleton is a design pattern that restricts the instantiation of a class to only one instance. Notable uses include controlling concurrency and creating a central point of access for an application to access its data store.This example demonstrate about How to clear Singleton instance in androidStep 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 ... Read More

How to retrieve documents from a collection in MongoDB?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25
To retrieve documents from a collection in MongoDB, you need to use find() method. The syntax is as follows:db.yourCollectionName.find();The above syntax will return all the documents from a collection in MongoDB. To understand the above syntax, let us create a collection with documents. The query to create documents are as follows:> db.retrieveAllStudents.insertOne({"StudentId":"STUD101", "StudentName":"David", "StudentAge":24}); {    "acknowledged" : true, "insertedId" : ObjectId("5c6bf5cf68174aae23f5ef4e") } > db.retrieveAllStudents.insertOne({"StudentId":"STUD102", "StudentName":"Carol", "StudentAge":22}); {    "acknowledged" : true, "insertedId" : ObjectId("5c6bf5e968174aae23f5ef4f") } > db.retrieveAllStudents.insertOne({"StudentId":"STUD103", "StudentName":"Maxwell", "StudentAge":25}); {    "acknowledged" : true, "insertedId" : ObjectId("5c6bf5f768174aae23f5ef50") } > db.retrieveAllStudents.insertOne({"StudentId":"STUD104", "StudentName":"Bob", "StudentAge":23}); {    "acknowledged" : true, "insertedId" : ... Read More

How to use action in JSP?

George John
Updated on 30-Jul-2019 22:30:25
The useBean action is quite versatile. It first searches for an existing object utilizing the id and scope variables. If an object is not found, it then tries to create the specified object.The simplest way to load a bean is as follows −Once a bean class is loaded, you can use jsp:setProperty and jsp:getProperty actions to modify and retrieve the bean properties.Following table lists out the attributes associated with the useBean action −Sr.No.Attribute & Description1classDesignates the full package name of the bean.2typeSpecifies the type of the variable that will refer to the object.3beanNameGives the name of the bean as specified ... Read More

How to parse currencies in JSP?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25
The tag is used to parse numbers, percentages, and currencies.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultValueNumeric value to read (parse)NoBodytypeNUMBER, CURRENCY, or PERCENTNonumberparseLocaleLocale to use when parsing the numberNoDefault localeintegerOnlyWhether to parse to an integer (true) or floating-point number (false)NofalsepatternCustom parsing patternNoNonetimeZoneTime zone of the displayed dateNoDefault time zonevarName of the variable to store the parsed numberNoPrint to pagescopeScope of the variable to store the formatted numberNopageA pattern attribute is provided that works just like the pattern attribute for the tag. However, in the case of parsing, the pattern attribute tells the parser what format to expect.Example ... Read More

LocalTime minusHours() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25
An immutable copy of a LocalTime object where some hours are subtracted from it can be obtained using the minusHours() method in the LocalTime class in Java. This method requires a single parameter i.e. the number of hours to be subtracted and it returns the LocalTime object with the subtracted hours.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalTime lt = LocalTime.now(); System.out.println("The current LocalTime is: " + lt); ... Read More

Iterate through Ennead Tuple in Java

Anvi Jain
Updated on 30-Jul-2019 22:30:25
To iterate through the Ennead Tuple, you can use them for a loop. That is it works in the same way like any other collection in Java. Let us first see what we need to work with JavaTuples. To work with Ennead class in JavaTuples, you need to import the following package −import org.javatuples.Ennead;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 ... Read More

What is the $unwind operator in MongoDB?

Anvi Jain
Updated on 30-Jul-2019 22:30:25
The $unwind operator in MongoDB is the same for each array, it returns the mapping document. Here is the demo of $unwind operator in MongoDB.To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.unwindOperatorDemo.insertOne({"StudentName":"Larry", "StudentAge":23, "StudentSubje ct":["C", "C++", "Java", "MongoDB"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c7ef5f3559dd2396bcfbfc8") }Display all documents from a collection with the help of find() method. The query is as follows −> db.unwindOperatorDemo.find().pretty();The following is the output −{    "_id" : ObjectId("5c7ef5f3559dd2396bcfbfc8"),    "StudentName" : "Larry",    "StudentAge" : ... Read More

Adding/ concatenating text values within a MySQL SELECT clause?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25
To add/ concatenate text values within a select clause, you can use concat() function.Let us create a tablemysql> create table ConcatenatingDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(20), -> UserCountryName varchar(20) -> ); Query OK, 0 rows affected (0.82 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into ConcatenatingDemo(UserName, UserCountryName) values('John', 'US'); Query OK, 1 row affected (0.14 sec) mysql> insert into ConcatenatingDemo(UserName, UserCountryName) values('Carol', 'UK'); Query OK, ... Read More

The toArray(T[]) method of AbstractSequentialList in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25
The difference between toArray() and toArray(T[] arr) is that both the methods returns an array containing all of the elements in this collection, but the latter has some additional features i.e. the runtime type of the returned array is that of the specified array.The syntax is as follows:public T[] toArray(T[] arr)Here, arr is the array into which the elements of this collection are to be stored, To work with the AbstractSequentialList class in Java, you need to import the following package:import java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList toArray() method in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class ... Read More

StringStream in C++ for Decimal to Hexadecimal and back

Nancy Den
Updated on 30-Jul-2019 22:30:25
In this section we will see how to convert Decimal to Hexadecimal string and also from Hexadecimal string to Decimal string in C++. For this conversion we are using the stringstream feature of C++.String streams are used for formatting, parsing, converting a string into numeric values etc. The Hex is an IO manipulator. It takes reference to an IO stream as parameter and returns reference to the string after manipulating it.In the following example we will see how to convert decimal number or hexadecimal number.Example Code#include #include using namespace std; main(){    int decimal = 61;    stringstream my_ss;   ... Read More
Advertisements