Java String.intern() The method intern() creates an exact copy of a String object in the heap memory and stores it in the String constant pool. Note that, if another String with the same contents exists in the String constant pool, then a new object won’t be created and the new… Continue Reading intern

Java String.indexOf() The method indexOf() returns the first occurrence index of a character or a String in another String. We can pass the index of the character to start searching from. Note that the method returns -1 if the passed value is not found. Available Signatures [source,java,gutter:,false] public int indexOf(int… Continue Reading index-of

Java String.contains() The method contains() checks if a String contains another String. The method accepts a CharSequence. So, we can pass any of the implementing classes to it such as StringBuilder and StringBuffer. Available Signatures [source,java,gutter:,false] public boolean contains(CharSequence s) Example [source,java,gutter:,true] @Test public void whenCallContains_thenCorrect() { String s =… Continue Reading contains

Java String.valueOf() The method valueOf() has several overloads that accept one parameter of different types and convert them to a String. Examples include boolean, char, char array, double, int and long. We can also convert a part of a char array to a String by passing: offset – the index… Continue Reading value-of

Java String.regionMatches() The method regionMatches() checks if two String regions are equal. Here are a few important points: ignoreCase specifies whether we should ignore the case of both Strings toffset determines the starting index of the first String other specifies the second String. ooffset specifies the starting index of the… Continue Reading region-matches

Java String.codePointAt() The method codePointAt() takes an int as a parameter and returns the code point at the specified index. A code point is a decimal value that the character is given in the Unicode standard. Available Signatures [source,java,gutter:,false] public int codePointAt(int index) Example [source,java,gutter:,true] @Test public void whenCallCodePointAt_thenDecimalUnicodeReturned() {… Continue Reading code-point-at

Java String.codePointCount() The method codePointCount() returns the number of Unicode code points in the specified range. The text range begins at the first index and ends at the second index – 1. Available Signatures [source,java,gutter:,false] public int codePointCount(int beginIndex, int endIndex) Example [source,java,gutter:,true] @Test public void whenCallCodePointCount_thenCorrect() { assertEquals(2, “abcd”.codePointCount(0,… Continue Reading code-point-count

Java String.split() The method split() splits a String into multiple Strings given the delimiter that separates them. The returned object is an array which contains the split Strings. We can also pass a limit to the number of elements in the returned array. If we pass 0 as a limit,… Continue Reading split