Java

Java Integer to String Conversion Examples

Java integer to string conversion is a very simple task. There are various ways to convert an integer to string in Java. Convert using Integer.toString(int i) Convert using String.valueOf(int i) Convert using Integer constructor, deprecated in Java 9. Convert using String.format() method Convert using String concatenation Convert using StringBuffer and StringBuilder classes Convert using DecimalFormat …

Java Integer to String Conversion Examples Read More »

Java String subSequence() Method Example

Java String subSequence() method returns a character subsequence from this string. This method is added to String class so that it can implement CharSequence interface. The subSequence() method internally calls substring() method. We can explicitly cast the returned CharSequence to a String object. It throws StringIndexOutOfBoundsException if the index values are invalid. String subSequence() Method …

Java String subSequence() Method Example Read More »

Java String substring() Method – Create a Substring

Java String class has two substring methods – substring(int beginIndex) and substring(int beginIndex, int endIndex). These methods return the substring from this string. If the index values are invalid, StringIndexOutOfBoundsException is thrown. The original string remains unchanged because strings are immutable in Java. Java String substring() methods call Arrays.copyOfRange() method, which further calls System.arraycopy() method. String …

Java String substring() Method – Create a Substring Read More »

Java String matches(regex) Examples

Java String matches(regex) method is used to test if the string matches the given regular expression or not. String matches() method internally calls Pattern.matches() method. This method returns a boolean value. If the regex matches the string, it returns “true”, otherwise “false”. If the regex pattern is invalid, PatternSyntaxException is thrown. Java String matches() Method …

Java String matches(regex) Examples Read More »