This example demonstrate about How to find edit text values start from Number is Even or Odd.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 edit text and button view to verify edit text data is starting with Even.Step 3− Add the following code to java/MainActivity.xmlpackage com.example.myapplication; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends ... Read More
The clear() method is inherited from the AbstractList class. It allows you to remove all the elements from the list.The syntax is as followspublic void clear()To work with the AbstractSequentialList class in Java, you need to import the following packageimport java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList clear() method in JavaExample Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo { public static void main(String[] args) { AbstractSequentialList absSequential = new LinkedList(); absSequential.add(250); absSequential.add(320); absSequential.add(400); absSequential.add(550); absSequential.add(600); absSequential.add(700); ... Read More
The day of the month for a particular LocalDate can be obtained using the getDayOfMonth() method in the LocalDate class in Java. This method requires no parameters and it returns the day of the month which can be in the range of 1 to 31.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalDate ld = LocalDate.parse("2019-02-14"); System.out.println("The LocalDate is: " + ld); System.out.println("The day of the month is: " + ld.getDayOfMonth()); } }OutputThe LocalDate is: 2019-02-14 ... Read More
For this, use the $not 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.notLikeOperatorDemo.insertOne({"StudentName":"John Doe"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8a29c393b406bd3df60dfc") } > db.notLikeOperatorDemo.insertOne({"StudentName":"John Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8a29cc93b406bd3df60dfd") } > db.notLikeOperatorDemo.insertOne({"StudentName":"John Taylor"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8a29df93b406bd3df60dfe") } > db.notLikeOperatorDemo.insertOne({"StudentName":"Carol Taylor"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8a2a1693b406bd3df60dff") } > db.notLikeOperatorDemo.insertOne({"StudentName":"David Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8a2a2693b406bd3df60e00") }Display all documents from ... Read More
To get the database data size in MongoDB, you can use stats() method. The syntax is as follows −db.stats();Let us use the database with the name ‘test’.Now, check the current database with the help of the following query −> db;The following is the output −testHere is the query to get database data size in MongoDB −> db.stats()The following is the output −{ "db" : "test", "collections" : 114, "views" : 0, "objects" : 391, "avgObjSize" : 83.0076726342711, "dataSize" : 32456, "storageSize" : 3211264, "numExtents" : 0, "indexes" : 120, "indexSize" ... Read More
The ResultSet class doesn’t provide any direct method to get the number of records in a table.The beforeFirst() method navigates the pointer/curser of the ResultSet object to its default position before first.In the same way the last() method positions the cursor at the last row of the ResultSet object.Using these methods you can find the number of records in the current ResultSet object.ExampleAssume we have a table named customers table with contents as shown below:+----+---------+-----+---------+----------------+ | ID | NAME | AGE | SALARY | ADDRESS | +----+---------+-----+---------+----------------+ | 1 | Amit | 25 | 3000.00 ... Read More
Yes, to retrieve multiple docs from MongoDB by id, use the $in operator. The syntax is as followsdb.yourCollectionName.find({_id:{$in:[yourValue1, yourValue2, yourValue3, ...N]}});Let us first create a collection with documents:> db.retrieveMultipleDocsByIdDemo.insertOne({"_id":10, "CustomerName":"John"}); { "acknowledged" : true, "insertedId" : 10 } > db.retrieveMultipleDocsByIdDemo.insertOne({"_id":14, "CustomerName":"Chris"}); { "acknowledged" : true, "insertedId" : 14 } > db.retrieveMultipleDocsByIdDemo.insertOne({"_id":20, "CustomerName":"Robert"}); { "acknowledged" : true, "insertedId" : 20 } > db.retrieveMultipleDocsByIdDemo.insertOne({"_id":25, "CustomerName":"Sam"}); { "acknowledged" : true, "insertedId" : 25 } > db.retrieveMultipleDocsByIdDemo.insertOne({"_id":30, "CustomerName":"Bob"}); { "acknowledged" : true, "insertedId" : 30 } > db.retrieveMultipleDocsByIdDemo.insertOne({"_id":34, "CustomerName":"Carol"}); { "acknowledged" : true, "insertedId" : 34 }Following is the query to display all documents ... Read More
To check if a Float is isInfinite, use the isInfinite() method and to check for NAN, use the isNaN() method.Example Live Demopublic class Demo { public static void main(String[] args) { float value1 = (float) 1 / 0; boolean res1 = Float.isInfinite(value1); System.out.println("Checking for isInfinite? = "+res1); float value2 = (float) Math.sqrt(9); boolean res2 = Float.isNaN(value2); System.out.println("Checking for isNan? = "+res2); } }OutputChecking for isInfinite? = true Checking for isNan? = false
You can use DATE_FORMAT() to set time data type to be only HH:MM. Following is the syntax −select DATE_FORMAT(yourColumnName, "%H:%i") AS anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable ( Arrivaltime time ); Query OK, 0 rows affected (0.61 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('08:20'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('05:40'); Query OK, 1 row affected (0.12 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-------------+ | Arrivaltime ... Read More
The following is an example to add items on runtime on a JComboBox in Java:Exampleimport java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; public class SwingDemo { public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox combo = new JComboBox(new String[] { "One", "Two", "Three", "Four", "Five", "Six" }); JButton add = new JButton("Add"); add.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ... Read More