Java equals() Method
The Java equals() method is used to compare objects. The equals() returns true if this object is equal to the given object. Otherwise, it returns false.
The Java equals() method is used to compare objects. The equals() returns true if this object is equal to the given object. Otherwise, it returns false.
toString() method returns the string or textual representation of an object.
The string specifies the object’s class which is followed by ‘@’ sign and the hashcode of the object (unsigned hexadecimal representation).
The Java printf method is used to write the formatted strings. The ‘f’ in printf keyword means formatted. The printf method belongs to the PrintStream and PrintWriter classes.
You may use a number of ways for reversing the strings in Java programs. If you are working with mutable strings by using StringBuilder or StringBuffer class then these classes have built-in reverse method.
StringBuffer and StringBuilder classes allow creating mutable sequence of characters. At any point of the program, you may change the content of StringBuffer/StringBuilder objects by using methods.
These methods can be used for number to string conversion: 1- toString() 2- String.valueOf, 3- String concatenation operator (+) 4- String.format() 5- StringBuffer 6- StringBuilder
The charAt(int) method returns the character in the specified string for given index number. The index of string starts at zero.
The Java indexOf returns the index of given character or substring for the first occurrence in the specified string. To get the last occurrence of the given substring or character, use the lastIndexOf() method.
Java has a built-in method for sorting the elements in collections like ArrayLists, LinkedList etc. The arrays class also has a built-in method “sort” that enables sorting the arrays only.
The continue statement is used to skip current iteration in the for and while loops in Java. In the case of Java for loop, the execution moves to the update counter as it meets the continue statement.
The split method breaks the specified string by the given regular expression delimiter and returns an array. The array contains substrings of the specified string after splitting.
For string comparison in Java, you may use the equals() and compareTo() methods. Both of these methods are explained below with examples.
Java comes up with built-in functions to let us convert strings to int. These methods are parseInt and valueOf. This is the topic of this tutorial.
The trim() method of Java can be used for removing the whitespaces from left and right of the given string. The leading or trailing spaces may occur particularly, as you are taking user input.
The String replace method of Java is used to replace the existing character(s) in the given string to the new given character(s). The replace method returns a new string which is the replaced string.