Validate Zip Code with Java Regular Expressions

Anvi Jain
Updated on 25-Jun-2020 15:04:40

478 Views

In order to match the ZIP code using regular expression, we use the matches method in Java. The java.lang.String.matches() method returns a boolean value which depends on the matching of the String with the regular expression.Declaration − The java.lang.String.matches() method is declared as follows −public boolean matches(String regex)Let us see a program which validates the ZIP code with Java Regular Expressions −Example Live Demopublic class Example {    public static void main( String[] args ) {       System.out.println(zipIndia("400709"));       System.out.println(zipUS("10060"));    }    // validate zip    public static boolean zipIndia( String z ) {     ... Read More

Implement Binary Search on Long Array in Java

George John
Updated on 25-Jun-2020 15:03:26

278 Views

Binary search on a long array can be implemented by using the method java.util.Arrays.binarySearch(). This method returns the index of the required long element if it is available in the array, otherwise it returns (-(insertion point) - 1) where the insertion point is the position at which the element would be inserted into the array.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo {    public static void main(String[] args) {       long long_arr[] = { 250L, 500L, 175L, 90L, 415L };       Arrays.sort(long_arr);       System.out.print("The sorted array ... Read More

Validate Phone with Java Regular Expressions

Krantik Chavan
Updated on 25-Jun-2020 15:01:54

373 Views

In order to match the phone using regular expression, we use the matches method in Java. The java.lang.String.matches() method returns a boolean value which depends on the matching of the String with the regular expression.Declaration − The java.lang.String.matches() method is declared as follows −public boolean matches(String regex)Let us see a program to validate a phone number with regular expressions −Example Live Demopublic class Example {    public static void main( String[] args ) {       System.out.println(phone("+91 1023456789"));    }    // validate zip    public static boolean phone( String z ) {       return z.matches("\+[0-9]*\s+\d{10}" );   ... Read More

Replace 'with' Using Java Regular Expressions

Nancy Den
Updated on 25-Jun-2020 15:01:20

2K+ Views

To replace *' with '^' using Java Regular Expressions, we need to use the replaceAll() method. The replaceAll() method returns a String replacing all the character sequence matching the regular expression and String after replacement.Declaration − The java.lang.String.replaceAll() method is declared as follows −public String replaceAll(String regex, String replaced)  Let us see a program to replace '*' with '^' using Java Regular Expressions −Example Live Demopublic class Example {    public static void main( String args[] ) {       String str = new String("H*e*l*l*o");       System.out.println( "Initial String : "+ str);       // replacing '*' ... Read More

Replace One String with Another Using Java Regular Expressions

Smita Kapse
Updated on 25-Jun-2020 15:00:57

7K+ Views

To replace one string with another string using Java Regular Expressions, we need to use the replaceAll() method. The replaceAll() method returns a String replacing all the character sequence matching the regular expression and String after replacement.Declaration − The java.lang.String.replaceAll() method is declared as follows −public String replaceAll(String regex, String replaced)  Let us see a program to replace one string with another string using Java Regular Expressions −Example Live Demopublic class Example {    public static void main( String args[] ) {       String str = new String("Good Harry Good");       System.out.println( "Initial String : "+ str); ... Read More

Replace All Words with Another String using Java Regular Expressions

Nancy Den
Updated on 25-Jun-2020 15:00:08

3K+ Views

To replace all words with another String using Java Regular Expressions, we need to use the replaceAll() method. The replaceAll() method returns a String replacing all the character sequence matching the regular expression and String after replacement.Declaration − The java.lang.String.replaceAll() method is declared as follows −public String replaceAll(String regex, String replaced)  Let us see a program to replace all words with another string with Java Regular Expressions −Example Live Demopublic class Example {    public static void main( String args[] ) {       String str = new String("Good Harry Good");       System.out.println( "Initial String : "+ str); ... Read More

Perform Animation on CSS Perspective Property

Arjun Thakur
Updated on 25-Jun-2020 15:00:07

139 Views

To implement animation on perspective property with CSS, you can try to run the following codeExampleLive Demo                    #demo1 {             position: relative;               margin-left: 120px;             height: 250px;             width: 350px;             padding: 10px;             border: 1px solid orange;             animation: myanim 3s infinite;             perspective: 200px;          }          @keyframes myanim {             50% {                perspective: 100px;             }          }          #demo2 {             padding: 90px;             position: absolute;             border: 1px solid black;             background-color: orange;             transform: rotateX(60deg);          }                     This is demo text in div1.          This is demo text in div2.          

Get the List of All Public Fields in Java

Smita Kapse
Updated on 25-Jun-2020 14:59:28

750 Views

An array of field objects is returned by the method java.lang.Class.getFields(). These field objects include the accessible public fields of the class that is represented by the class object.Also, the getFields() method returns a zero length array if the class or interface has no public fields that are accessible or if a primitive type, array class or void is represented in the Class object.A program that demonstrates this is given as follows −Example Live Demoimport java.lang.reflect.*; public class Demo {    public static void main(String[] argv) throws Exception {       Class c = java.lang.Thread.class;       Field[] fields ... Read More

Perform Animation on CSS Padding Top Property

Daniol Thomas
Updated on 25-Jun-2020 14:59:08

281 Views

To implement animation on padding-top property with CSS, you can try to run the following code −ExampleLive Demo                    div {             width: 350px;             height: 150px;             outline: 3px solid maroon;             animation: myanim 3s infinite;          }          @keyframes myanim {             30% {                padding-top: 60px;             }          }                     CSS padding-top property          

Remove Preference from a Preference Node in Java

Nancy Den
Updated on 25-Jun-2020 14:58:52

538 Views

In order to remove a preference from a preference node in Java, we use the remove() method. The remove method() removes all the values associated with the specified key in the preference node.Declaration − The java.util.prefs.Preferences.remove() method is declared as follows −public abstract void remove (String key)where key is the key whose preference is to be removedThe remove methods throws the following exceptions −NullPointerExceptionThis exception occurs when the key is nullIllegalStateExceptionThis exception is thrown when the ancestor node is removed by the removeNode() method.Let us see a program to remove the preference from a preference node −Example Live Demoimport java.util.prefs.Preferences; public ... Read More

Advertisements