Java String

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 »