At first, let us create and array of strings:String[] strArr = { "ABCD", "AB", "ABCDEFG", "ABC", "A", "ABCDE", "ABCDEF", "ABCDEFGHIJ" };Now, for shortest to longest pattern, for example A, AB, ABC, ABCD, etc.; get the length of both the string arrays and work them like this:Arrays.sort(strArr, (str1, str2) -> str1.length() - str2.length());The following is an example to sort array of strings by their lengths with shortest to longest pattern:Exampleimport java.util.Arrays; public class Demo { public static void main(String[] args) { String[] strArr = { "ABCD", "AB", "ABCDEFG", "ABC", "A", "ABCDE", "ABCDEF", "ABCDEFGHIJ" }; ... Read More
Cryptocurrency like Bitcoin uses the Block chain as a decentralized, distributed, public digital ledger that records all the transactions of the Bitcoin. Block Chain has a unique feature of storing the value of previous block as a hash value in the current block, which makes it impossible to alter any block without changing all the subsequent blocks.The miners create a block and verify it and will be rewarded for using their CPU power to do so. The block which gets more than 50% consensus will be added to the block chain. During the verification of Block, the miners will complete ... Read More
ResultSet holdability determines whether the ResultSet objects (cursors) should be closed or held open when a transaction (that contains the said cursor/ResultSet object) is committed using the commit() method of the Connection interface.The getResultSetHoldability() method of the DatabaseMetaData interface retrieves the default holdability for the ResultSet objects of the underlying database.This method returns an integer value representing the default ResultSet holdability, which will be either 1 or 2 where, 1 indicates the value HOLD_CURSORS_OVER_COMMIT. If the holdability of the ResultSet object is set to this value. Whenever you commit/save a transaction using the commit() method of the Connection interface, the ResultSet ... Read More
You can use Date() along with $gte operator to find objects created last week. Here the curdate is as follows in my system −> new Date(); ISODate("2019-05-14T08:32:42.773Z")Let us first create a collection with documents −> db.findObectInLastWeekDemo.insertOne({"ShippingDate":new ISODate("2019-05-01")}); { "acknowledged" : true, "insertedId" : ObjectId("5cda7dc4bf3115999ed511e0") } > db.findObectInLastWeekDemo.insertOne({"ShippingDate":new ISODate("2019-05-02")}); { "acknowledged" : true, "insertedId" : ObjectId("5cda7dc4bf3115999ed511e1") } > db.findObectInLastWeekDemo.insertOne({"ShippingDate":new ISODate("2019-05-08")}); { "acknowledged" : true, "insertedId" : ObjectId("5cda7dc4bf3115999ed511e2") } > db.findObectInLastWeekDemo.insertOne({"ShippingDate":new ISODate("2019-05-07")}); { "acknowledged" : true, "insertedId" : ObjectId("5cda7dc4bf3115999ed511e3") } > db.findObectInLastWeekDemo.insertOne({"ShippingDate":new ISODate("2019-05-09")}); { "acknowledged" : true, "insertedId" : ObjectId("5cda7dc4bf3115999ed511e4") } > ... Read More
Let’s first see how we set text in a components tooltip −JLabel label3 = new JLabel("Password", SwingConstants.CENTER); label3.setToolTipText("Enter Password");To display multiple lines of text in a tooltip, use . Here, we have used the HTML tag for new line and that would create multiple lines of text in the tooltip −label3.setToolTipText("" + "This will create multiple lines for the" + "" + "component! Yay!" + "");The following is an example to display multiple lines of text in a component’s tooltip −Examplepackage my; import java.awt.GraphicsEnvironment; import java.awt.GridLayout; import java.awt.Point; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.SwingConstants; import ... Read More
For year and month date fetching, you can use YEAR() and MONTH() function in MySQL. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ShippingDate datetime ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ShippingDate) values('2019-01-31'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(ShippingDate) values('2018-12-01'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(ShippingDate) values('2019-06-02'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(ShippingDate) values('2019-11-18'); Query OK, 1 row ... Read More
Prufer code uniquely identifies a tree which is given by user as a graph representation with labels from 1 to p. This tree consist p(value is given by user) labels of node. It has sequence of p – 2 values.AlgorithmBegin Declare i, j, ver, edg, minimum, p to the integer datatype. Print “Enter the number of vertexes: ”. Enter the value of ver. Initialize edg = ver-1. Declare EDG[edg][2], DG[ver+1] to the integer datatype. Initialize DG[ver+1] = {0}. Print “This tree has (value of edg) edges for (value of ver) vertexes”. ... Read More
The Input Checkbox type property returns/sets type of Input Checkbox.SyntaxFollowing is the syntax −Returning string valueinputCheckboxObject.typeSetting type to string valueinputCheckboxObject.type = stringValueString ValuesHere, “stringValue” can be the following -stringValueDetailscheckboxIt defines that input type is checkboxradioIt defines that input type is radiotextIt defines that input type is textExampleLet us see an example of Input Checkbox type property − Live Demo Type Attribute of Checkbox Other: Change type of input var typeOfInput = document.getElementById("formCheckbox"); var displayDiv = document.getElementById("displayDiv"); displayDiv.textContent = 'Type of Input: ' + typeOfInput.type function changeType(){ ... Read More
The HTML DOM Input Text size property returns/sets the size property for input text. If not defined this property returns ‘20’.SyntaxFollowing is the syntax −Returning size attributeinputTextObject.sizeSet size property to a numberinputTextObject.size = numberExampleLet us see an example of Input Text size property − Live Demo Input Text size form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } Text-size ... Read More
If you have done little-bit of programming in python, you have seen the word “**args” and “**kwargs” in python functions. But what exactly they are?The * and ** operators did different operations which are complementary to each other depending on where we are using them.So when we are using them in method definition, like -def __init__(self, *args, **kwargs): passAbove operation is called ‘packing” as it pack all the arguments into one single variable that this method call receives into a tuple called args. We can use name other than args, but args is the most common and pythonic way of ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP