An immutable copy of a LocalTime object where some hours are added to it can be obtained using the plusHours() method in the LocalTime class in Java. This method requires a single parameter i.e. the number of hours to be added and it returns the LocalTime object with the added 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); System.out.println("The LocalTime with 3 hours added is: ... Read More
Let us first create a new table and understand the concept in continuationmysql> create table StoredProcedureInsertDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(20), -> UserAge int -> ); Query OK, 0 rows affected (0.63 sec)Here is the query to create a stored procedure to insert data in to the tablemysql> DELIMITER // mysql> create procedure procedure_InsertIntoTable(IN FirstName VARCHAR(100), IN Age INT) -> BEGIN -> insert into StoredProcedureInsertDemo(UserName, UserAge) values (FirstName, Age); -> END -> // Query OK, 0 rows affected (0.34 sec) mysql> DELIMITER ;Call ... Read More
Remove an element at a specified position from the list using the remove() method. The position is to be set as index parameter in the method itself. It returns the element which is removed.The syntax is as follows:public E remove(int index)Here, index is the index from where you want to delete the element.To work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to implement remove() method of the AbstractlList class in Java:Example Live Demoimport java.util.ArrayList; import java.util.AbstractList; public class Demo { public static void main(String[] args) { AbstractList myList = new ArrayList(); ... Read More
Before getting into the example, we should know what is intent filter in android. An intent filter is an instance of the IntentFilter class. Intent filters are helpful while using implicit intents, It is not going to handle in java code, we have to set it up in AndroidManifest.xml. Android must know what kind of intent it is launching so intent filters give the information to android about intent and actions.Before launching intent, android going to test action test, category test and data test. This example demonstrate about how to use custom intent filters to a broadcast receiver in android.Step ... Read More
To update only specific field, you can use $set operator. Let us first create a collection with documents>db.updateOnlySpecificFieldDemo.insertOne({"EmployeeName":"John", "EmployeeCountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9ea849d628fa4220163b72") } >db.updateOnlySpecificFieldDemo.insertOne({"EmployeeName":"Larry", "EmployeeCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9ea853d628fa4220163b73") } >db.updateOnlySpecificFieldDemo.insertOne({"EmployeeName":"David", "EmployeeCountryName":"AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9ea85bd628fa4220163b74") }Following is the query to display all documents from a collection with the help of find() method> db.updateOnlySpecificFieldDemo.find().pretty();This will produce the following output{ "_id" : ObjectId("5c9ea849d628fa4220163b72"), "EmployeeName" : "John", "EmployeeCountryName" : "UK" } { "_id" : ObjectId("5c9ea853d628fa4220163b73"), "EmployeeName" : "Larry", "EmployeeCountryName" : ... Read More
Create a List in Java −List< String >list = Arrays.asList("P", "Q", "R", "P", "T", "P", "U", "V", "W", "X", "W" );Now, let’s say you want to get the frequency of element P. For that, use the Collections.frequency() method −Collections.frequency(list, "P");A shown above, we can find the occurrence of any letter as well −Collections.frequency(list, "T");Example Live Demoimport java.util.Arrays; import java.util.Collections; import java.util.List; public class Demo { public static void main(String[] args) { Listlist = Arrays.asList("P", "Q", "R", "P", "T", "P", "U", "V", "W", "X", "W" ); int checkOccurrence = Collections.frequency(list, "P"); System.out.println("Occurrence ... Read More
There is no double equal sign concept. It can be used to compare two values. If you use double equal sign(==) in MySQL, you will get an error message.Let us verify the concept is true or not. Declare a variable −mysql> set @Number=10; Query OK, 0 rows affected (0.00 sec)Now, compare the above variable value with 10. If both the values are same then the result will be 1 otherwise 0.Using double equal sign −mysql> select 10==@Number;This will produce the following output i.e. an error −ERROR 1064 (42000): You have an error in your SQL syntax; check the manual ... Read More
The method java.io.File.list() is used to obtain the list of the files and directories in the specified directory defined by its path name. This list of files is stored in a string array. If the length of this string array is greater than 0, then the specified directory is not empty. Otherwise, it is empty.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo { public static void main(String[] args) { File directory = new File("C:\JavaProgram"); if (directory.isDirectory()) { String[] files = directory.list(); ... Read More
A read-only char buffer can be created using the contents of a buffer with the method asReadOnlyBuffer() in the class java.nio.CharBuffer. The new buffer cannot have any modifications as it is a read-only buffer. However, the capacity, positions, limits etc. of the new buffer are the same as the previous buffer.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'); ... Read More
To count the number of items in an array, you can use $size operator. The syntax is as follows:db.yourCollectionName.aggregate({$project:{anyFieldName:{$size:"$yourArrayName"}}}).prett y();To understand the above syntax, let us create a collection with document. The query to create a collection with document is as follows:>db.getSizeOfArray.insertOne({"StudentId":1, "StudentName":"Larry", "StudentMarks":[87, 34, 5 6, 77, 89, 90]}); { "acknowledged" : true, "insertedId" : ObjectId("5c6ebc536fd07954a4890680") } >db.getSizeOfArray.insertOne({"StudentId":2, "StudentName":"Sam", "StudentMarks":[90, 76, 56 ]}); { "acknowledged" : true, "insertedId" : ObjectId("5c6ebc6b6fd07954a4890681") } >db.getSizeOfArray.insertOne({"StudentId":3, "StudentName":"Carol", "StudentMarks":[90, 76]}) ; { "acknowledged" : true, "insertedId" : ObjectId("5c6ebc7a6fd07954a4890682") }Now you can display all documents from a collection with ... Read More