
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
Karthikeya Boyini has Published 2193 Articles

karthikeya Boyini
298 Views
Use the Short.parseShort() method in Java to convert a String to a short.Let’s say the following is our string.String str = “76”;Now, the parseShort() method will convert the string to short.byte val = Byte.parseByte(str);Example Live Demopublic class Demo { public static void main(String[] args) { String str = "76"; short val = Short.parseShort(str); System.out.println(val); ... Read More

karthikeya Boyini
10K+ Views
Here is our string.String strTime = "20:15:40";Now, use the DateFormat to set the format for date.DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");Parse the string of time to time object.Date d = dateFormat.parse(strTime);The following is the complete example.Example Live Demoimport java.text.DateFormat; import java.util.Date; import java.text.SimpleDateFormat; public class Demo { public static void main(String[] args) throws Exception { String strTime = "20:15:40"; DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss"); ... Read More

karthikeya Boyini
2K+ Views
Use the lastIndexOf() method to find the last occurrence of a character in a string in Java.Let’s say the following is our string.String myStr = "Amit Diwan";In the above string, we will find the last occurrence of character ‘i’myStr.lastIndexOf('i');The following is the complete example.Example Live Demopublic class Demo { public static void main(String[] args) { String myStr = "Amit Diwan"; ... Read More

karthikeya Boyini
418 Views
Use the indexOf() method to search for a substring from a given position.Let’s say the following is our string.String myStr = " pqrstuvwxyzpqrst";Searching for the substring “pqrs” in the string. We are beginning the index from 3 for our search.int begnIndex = 3; strLastIndex = myStr.indexOf("pqrs", begnIndex);Example Live Demopublic class Demo { ... Read More

karthikeya Boyini
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: "); ... Read More

karthikeya Boyini
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) { ... Read More

karthikeya Boyini
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 ... Read More

karthikeya Boyini
8K+ Views
To replace the first occurrence of a character in Java, use the replaceFirst() method.Here is our string.String str = "The Haunting of Hill House!";Let us replace the first occurrence of character “H”str.replaceFirst("(?:H)+", "B");The following is the complete example.Example Live Demopublic class Demo { public static void main(String[] args) { String str = "The Haunting of Hill House!"; ... Read More

karthikeya Boyini
3K+ Views
To concatenate null to a string, use the + operator.Let’s say the following is our string.String str = "Demo Text";We will now see how to effortlessly concatenate null to string.String strNULL = str + "null";The following is the final example.Example Live Demopublic class Demo { public static void main(String[] args) { String str = "Demo Text"; ... Read More

karthikeya Boyini
243 Views
To compare string for equality in Java, use the equals() method. Let us see some examples wherein we have checked for same as well as different string values.Example Live Demopublic class Demo { public static void main(String[] args) { String one = "x"; String two = "x"; if(one.equals(two)) { ... Read More