String manipulation is an important part of any general purpose programming language. For example, we may want to extract some data from a given String or text. In this case, performing Substring is very important. This post will give some ways on how we can extract Subtring in the Groovy language. And since this is Groovy, some are just very cool.
Java hashCode() method has a close relationship with the equals() method as they complement and are used together. On a high level, the equals method should inspect the relevant data of two instances to determine if they are logically the same object. What internal data the equals() method used should also be used to generate the hashCode() value of a specific object instance. Below are more detailed discussion with code examples about Java hashCode.
When we are dealing with a handful of data of the same type, we can use a different variable for each. But if we are working with arbitrarily more numbers of data of same type, array can be a good choice because it is a simple data structure to work with. List or Set is also a good choice, but arrays is much simpler to manipulate and work with. We explore below how do we work with Java Char Array. We will check different common scenario we encounter when working with char arrays.
Although a very old and dated data structure, array is still a very popular data structure to work with a collection of objects. This is because manipulation of arrays is very simple to learn and use. The only issue is it lacks advance features than can be found in the Collections API. For this tutorial, we will show how to Add elements to an Array in Java.
Byte Array is a convenient data structure that has many use cases. One scenario is when serializing some object to a file, and so we need to convert object to byte array when we write to file, and convert back from byte array to objects when we read from file. Another scenario is when sending data from one machine to another. Complex data structure is converted to a byte array before sending over the network, and on the other end the byte array is converted back to the original data structure. One of the simplest type of Object that we can convert to and from byte array is a String. This post will show how to convert Java Byte Array To String that can be applied to the use cases mentioned earlier.
Hash code in Java is very important specially with the introduction of the Java Collections API. Many classes in the Collections API uses hash code as a convention. So what exactly is a hash code? It is an integer representation of a specific Object instance. The assumption is that this integer value should be the same whenever the hashCode() method is invoked on the same Object more than once during an execution of a Java application. The hashCode method must consistently provide the same value provided that no internal data used in equals is modified on the Object. We should not worry about this on Immutable objects as internal data is not change throughout it's lifetime. In addition, if two objects are equal using the equals method of the class, then the hashCode of both should return the same value. This implies that the hashCode should be based on the data used in equals method. Lastly, it is not required that two unequal Objects should have different hashCode. Since hashCode is common to all classes as it is implemented in the Object class, we will discuss on how it is implemented in the String class of Java. This post will explain and give examples on Java String HashCode.
The trend in the software development industry is going in the direction of making things easier and simpler. This is why languages such as Groovy is getting popular as time pass by. And there has been a big surge in popularity of Groovy when Gradle became the recent standard in Build Automation System. Groovy is just hands down concise and simpler than Java and makes developer time so much more efficient. In this post, we will explore how to use Groovy Maps by providing examples for different use cases.
Groovy is now getting popular with the help of the increasing user base of Gradle. Groovy language is exceptional in being a very concise and powerful language. Compared to Java, writing things just needs very short code that is human friendly and makes developers happy. One common task we deal in most generic programming language is manipulating Strings and List. Below is an example on how to convert a Groovy List to String.
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.