String is one of the most fundamental data structure. It is versatile and useful for many cases. This is why Strings are used in many cases instead of using more restrictive data structure. But sometimes we need to compare two or more Strings for specific programming needs. Below are som examples on how we can compare Strings in Java.
String is an all around data structure for saving information because it can handle arbitrary sequence of characters. Often times, it is also used to store numeric, date, or other type of information. Sometimes we need to convert a String object to another data structure. For example, if an HTML form submits a date information to the server, each data in the form are passed as String. In this case, we would need to convert the String to Date such that other computations can be performed. For example, determining the age based on birth date and current date. Below are some ways on how we could convert a String into Date for some specific condition or method.
Strings and Arrays are two of the most popular data type in Java and in other popular language. String are able to represent a series of characters that is viewed as a single entity. While arrays are used to hold multiple values in the most simple way. But how do we convert a String like "One,Two,Three" into an array splitting into 3 different words or string? Below are some examples on in Java on how to split String into Array.
It is a common scenario in programming when we wish to check if one String contains a specific substring. For example, we wish to test if the String "The quick brown fox" contains the substring "brown". The Java String class has a method contains() that can help with this case. Below are examples on how to use Java String's contains method.
When dealing with numbers that are not whole, the type double is usually used for convenience because it is primitive and has good precision. However, when a double variable is converted to String, most of the time the result is in exponential or scientific notation. Below are some examples on how to perform in Java the conversion from double to String without exponential or scientific notation.
Java objects have the toString() method to convert the instance to it's String representation. If you will try to invoke the toString() method of an Array, the result will be some weird String like [I@70f9f9d8. This does not seems logical, say for example you wish to write the String to logs. It is more useful to convert a Java Array to a String that gives human understandable results. Below are some examples on how to do that.
A Java String Array is an object that holds a fixed number of String values. Arrays in general is a very useful and important data structure that can help solve many types of problems. It's simplicity on how to access contents through index makes it powerful yet user-friendly. Here are some examples on how to use String Array in Java.
The Java String replace method can be used to replace a character or a string sequence from an instance of a String, with a new value of character or a String sequence. This is very useful in problems that needs String manipulations. ...
Float is one of the most basic data type in Java for representing numerical values with decimal places. A common situation is when we want to convert a float value to String. Below are some examples on how to convert float to String in Java using two decimal places.