The Matcher can be reset using the java.util.regex.Matcher.reset() method. This method returns the reset Matcher.A program that demonstrates the method Matcher.reset() in Java regular expressions is given as follows:Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class MainClass { public static void main(String args[]) { Pattern p = Pattern.compile("(a*b)"); Matcher m = p.matcher("caaabcccab"); System.out.println("The input string is: caaabcccab"); System.out.println("The Regex is: (a*b)"); System.out.println(); while (m.find()) { System.out.println(m.group()); } m.reset(); System.out.println("The ... Read More
The d format is used in Java Date to format day like 1, 2, 3, 4, etc. Let us use it.// displaying day in d format SimpleDateFormat simpleformat = new SimpleDateFormat("d"); String strDay = simpleformat.format(new Date()); System.out.println("Day in d format = "+strDay);Above, we have used the SimpleDateFormat class, therefore the following package is imported −import java.text.SimpleDateFormat;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ... Read More
In MySQL, now() can be used to insert current date/time. The syntax is as follows −insert into yourTableName values(now());To understand the above concept of inserting current date/time in the table, let us first create a table −mysql> create table CurrentDateTimeDemo −> ( −> YourTime datetime −> ); Query OK, 0 rows affected (0.58 sec)Inserting current date/time using now(). The query is as follows −mysql> insert into CurrentDateTimeDemo values(now()); Query OK, 1 row affected (0.20 sec)Now you can check the current date/time has been inserted or not −mysql> select *from CurrentDateTimeDemo;The following ... Read More
The java.util.regex.Pattern.matches() method matches the regular expression and the given input. It has two parameters i.e. the regex and the input. It returns true if the regex and the input match and false otherwise.A program that demonstrates the method Pattern.matches() in Java regular expressions is given as follows:Example Live Demoimport java.util.regex.Pattern; public class Demo { public static void main(String args[]) { String regex = "a*b"; String input = "aaab"; System.out.println("Regex: " + regex); System.out.println("Input: " + input); boolean match = Pattern.matches(regex, input); ... Read More
When the full name is provided, the initials of the name are printed with the last name is printed in full. An example of this is given as follows −Full name = Amy Thomas Initials with surname is = A. ThomasA program that demonstrates this is given as follows −Example Live Demoimport java.util.*; public class Example { public static void main(String[] args) { String name = "John Matthew Adams"; System.out.println("The full name is: " + name); System.out.print("Initials with surname is: "); int len = name.length(); ... Read More
The dd format in Java Date is like 05, 06, 07, 08, 09, etc. i.e. with two-letter digit. Let us use it.// displaying day in dd format SimpleDateFormat simpleformat = new SimpleDateFormat("dd"); String strDay = simpleformat.format(new Date()); System.out.println("Day in dd format = "+strDay);Above, we have used the SimpleDateFormat class, therefore the following package is imported −import java.text.SimpleDateFormat;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ... Read More
You can count multiple COUNT() for multiple conditions in a single query using GROUP BY.The syntax is as follows -SELECT yourColumnName, COUNT(*) from yourTableName group by yourColumnName;To understand the above syntax, let us first create a table. The query to create a table is as follows.mysql> create table MultipleCountDemo -> ( -> Id int, -> Name varchar(100), -> Age int -> ); Query OK, 0 rows affected (2.17 sec)Insert records in the table using insert command. The query is as follows.mysql> insert into MultipleCountDemo values(1, 'Carol', 21); Query OK, 1 row affected (0.27 sec) mysql> insert into MultipleCountDemo values(2, ... Read More
Select non-empty column values using NOT IS NULL and TRIM() function. The syntax is as follows.SELECT * FROM yourTableName WHERE yourColumnName IS NOT NULL AND TRIM(yourColumnName) ' ';You can select non-empty value as well as whitespace from column using the same TRIM() function.To understand the syntax we discussed above, let us create a table. The query to create a table is as follows −mysql> create table SelectNonEmptyValues -> ( -> Id int not null auto_increment, -> Name varchar(30), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.62 sec)Insert records in the table ... Read More
Literary Devices are the peculiar structures used by writers in their works in order to convey their messages in a simple manner to the readers.The various literary devices used in English Literature areAlliteration, Analogy, Allegory, Anaphora, Metaphor, Simile, Aphorism, Oxymoron, Onomatopoeia, Eulogy, Elegy, and others.Alliteration: It is the device in which a number of words, having the same first consonant sound, occur close together in a series.Example- He had a haunting hat.Analogy: It is the comparison of an idea or a thing with another. Metaphors and similes are used to draw analogies. A metaphor is an implied comparison while a ... Read More
The Email address can be validated using the java.util.regex.Pattern.matches() method. This method matches the regular expression for the E-mail and the given input Email and returns true if they match and false otherwise.A program that demonstrates this is given as follows:Example Live Demopublic class Demo { static boolean isValid(String email) { String regex = "^[\w-_\.+]*[\w-_\.]\@([\w]+\.)+[\w]+[\w]$"; return email.matches(regex); } public static void main(String[] args) { String email = "john123@gmail.com"; System.out.println("The E-mail ID is: " + email); System.out.println("Is the above E-mail ID valid? " + ... Read More