
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7442 Articles for Java

330 Views
We have the following string −String str = "This is demo text, and demo line!";To tokenize the string, let us split them after every period (.) and comma (,)String str = "This is demo text, and demo line!";The following is the complete example.Example Live Demopublic class Demo { public static void main(String[] args) { String str = "This is demo text, and demo line!"; String[] res = str.split("[, .]", 0); for(String myStr: res) { System.out.println(myStr); } } }OutputThis is demo text and demo line!

5K+ Views
Use equals() in Java to check for equality between two strings.Use equalsIgnoreCase() in Java to check for equality between two strings ignoring the case.Let’s say the following are our two strings −String one = "qwerty"; String two = "Qwerty";Both are equal, but the case is different. Since the method ignores case, both of these strings would be considered equal using equalsIgnoreCase() method.Here, we are checking the same −if(one.equalsIgnoreCase(two)) { System.out.println("String one is equal to two (ignoring the case) i.e. one==two"); }else{ System.out.println("String one is not equal to String two (ignoring the case) i.e. one!=two"); }However, under ... Read More

752 Views
There are two ways to determine if two objects are equal in Javal: the.equals() method and the == operator. The.equals() function compares the contents of two objects. The == operator compares the references of two objects. When you create an object with the new operator, it gets assigned a specified memory location in the heap. Tak, for example, two objects are having the same data. Even if the two objects kept in different sections of memory, the.equals() method will return true. The == operator returns true if two objects get stored in memory at the exact same location. Differences between ... Read More

4K+ Views
Use the System.getProperty() method in Java to get the Operating System name.It’s syntax is −String getProperty(String key)Above, the key is the name of the system property. Since, we want the OS name, therefore we will add the key as −os.nameExample Live Demopublic class Demo { public static void main(String[] args) { System.out.print("Operating System: "); System.out.println(System.getProperty("os.name")); } }OutputOperating System: Linux

774 Views
To return all the default systems properties in Java, firstly use the System.getProperties() method.java.util.Properties prop = System.getProperties();After that, use the list() method to list all of them.prop.list(System.out);Example Live Demopublic class Demo { public static void main(String[] args) { java.util.Properties prop = System.getProperties(); System.out.println("Here are the Properties:"); prop.list(System.out); } }OutputHere are the Properties: java.runtime.name=OpenJDK Runtime Environment sun.boot.library.path=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0... java.vm.version=25.141-b16 java.vm.vendor=Oracle Corporation java.vendor.url=http://java.oracle.com/ path.separator=: java.vm.name=OpenJDK 64-Bit Server VM file.encoding.pkg=sun.io user.country=US sun.java.launcher=SUN_STANDARD sun.os.patch.level=unknown java.vm.specification.name=Java Virtual Machine Specification user.dir=/home/cg/root/3757524 java.runtime.version=1.8.0_141-b16 java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment java.endorsed.dirs=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0... os.arch=amd64 java.io.tmpdir=/tmp line.separator= java.vm.specification.vendor=Oracle Corporation os.name=Linux sun.jnu.encoding=UTF-8 java.library.path=/home/cg/root/GNUstep/Library/Librari... java.specification.name=Java Platform API Specification java.class.version=52.0 sun.management.compiler=HotSpot 64-Bit Tiered Compilers os.version=3.10.0-862.9.1.el7.x86_64 user.home=? user.timezone= java.awt.printerjob=sun.print.PSPrinterJob ... Read More

2K+ Views
To return all the system properties in Java, firstly use the System.getProperties() method.java.util.Properties prop = System.getProperties();After that, use the list() method to list all of them.prop.list(System.out);Example Live Demopublic class MainClass { public static void main(String[] args) { java.util.Properties prop = System.getProperties(); prop.list(System.out); } }Outputjava.runtime.name=OpenJDK Runtime Environment sun.boot.library.path=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0... java.vm.version=25.141-b16 java.vm.vendor=Oracle Corporation java.vendor.url=http://java.oracle.com/ path.separator=: java.vm.name=OpenJDK 64-Bit Server VM file.encoding.pkg=sun.io user.country=US sun.java.launcher=SUN_STANDARD sun.os.patch.level=unknown java.vm.specification.name=Java Virtual Machine Specification user.dir=/home/cg/root/3757524 java.runtime.version=1.8.0_141-b16 java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment java.endorsed.dirs=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0... os.arch=amd64 java.io.tmpdir=/tmp line.separator= java.vm.specification.vendor=Oracle Corporation os.name=Linux sun.jnu.encoding=UTF-8 java.library.path=/home/cg/root/GNUstep/Library/Librari... java.specification.name=Java Platform API Specification java.class.version=52.0 sun.management.compiler=HotSpot 64-Bit Tiered Compilers os.version=3.10.0-862.9.1.el7.x86_64 user.home=? user.timezone= java.awt.printerjob=sun.print.PSPrinterJob file.encoding=UTF-8 java.specification.version=1.8 user.name=? java.class.path=/home/cg/root/GNUstep/Library/Librari... java.vm.specification.version=1.8 sun.arch.data.model=64 java.home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0... sun.java.command=MainClass java.specification.vendor=Oracle Corporation user.language=en ... Read More

681 Views
In this article, we will learn to extract the maximum numeric value from a string using Java’s regex. While Java provides several ways to handle string manipulation, regular expressions (regex) offer a powerful and efficient tool for such tasks. Problem Statement The maximum numeric value is extracted from an alphanumeric string. An example of this is given as follows − Input String = abcd657efgh234 Output Maximum numeric value = 657 Using Java Regex and Pattern Class Java provides the Pattern and Matcher classes to work with regular expressions. The Pattern class compiles a regular expression, and the Matcher class is ... Read More

458 Views
Use the charAt() method in Java to get a character located at a specified index.Let’s say the following is our string.String str = "Laptop...";Finding character at 3rd position.str.charAt(2);The following is the final example.Example Live Demopublic class Demo { public static void main(String[] args) { String str = "Laptop..."; System.out.println("String: "+str); System.out.println("Character at position 3 = " +str.charAt(2)); } }OutputString: Laptop... Character at position 3 = p

167 Views
The compareTo(obj) method compares this String to another Object.The value 0 is returned if the argument is a string lexicographically equal to this string; a value less than 0 if the argument is a string lexicographically greater than this string; and a value greater than 0 if the argument is a string lexicographically less than this string.We have the following two strings −String str1 = "tom"; String str2 = "tim";Let us check them for all the return values.if(str1.compareTo(str2) > 0) { System.out.println("First string is greater!"); } if(str1.compareTo(str2) == 0) { System.out.println("First string is equal to Second string!"); } if(str1.compareTo(str2) 0) { System.out.println("First string ... Read More

234 Views
Use equalsIgnoreCase() in Java to check for equality between two strings ignoring the case.Let’s say the following are our two strings.String one = "rocky"; String two = "Rocky";Both are equal, but the case is different. Since the method ignore case, both of these strings would be considered equal.Here, we are checking the same.if(one.equalsIgnoreCase(two)) { System.out.println("String one is equal to two (ignoring the case) i.e. one==two"); }else{ System.out.println("String one is not equal to String two (ignoring the case) i.e. one!=two"); }The following is the complete example.Example Live Demopublic class Demo { public static void main(String[] args) { String one = "rocky"; ... Read More