Java String.isEmpty() The method isEmpty() is a convenience method that checks if the size of a String is equal to zero. Available Signatures [source,java,gutter:,false] public boolean isEmpty() Example [source,java,gutter:,true] @Test public void whenCallIsEmpty_thenCorrect() { String s1 = “”; assertTrue(s1.isEmpty()); }

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.getBytes() The method getBytes() encodes a String into a byte array using the platform’s default charset if no argument is passed. We can pass a specific Charset to be used in the encoding process, either as a String object or a String object. Available Signatures [source,java,gutter:,false] public byte[] getBytes()… Continue Reading get-bytes

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

Java String.concat() The method concat() concatenates two Strings. Simply put, it connects them into a single String. If the length of the argument is 0, then the method simply returns the String object. Available Signatures [source,java,gutter:,false] public String concat(String str) Example [source,java,gutter:,true] @Test public void whenCallConcat_thenCorrect() { assertEquals(“elephant”, “elep”.concat(“hant”)); }

Java String.copyValueOf() The method copyValueOf() converts a character array to a String with the same contents. This method is equivalent to valueOf(char[]). The offset represents the index of the first element to start copying from, and the count represents the number of elements to copy. Available Signatures [source,java,gutter:,false] public static… Continue Reading copy-value-of

Java String.String() String objects can be created by either using literals: String s = “a string”; or by calling one of the constructors: String s = new String(“a string”); If we use the String literal, it’ll try to reuse already existing object from the String constant pool. On the other hand,… Continue Reading constructor

Java String.format() The method format() formats a String using a format String and arguments. For example, characters ‘s’ and ‘S’ evaluate to “null” if the argument arg is null. If arg implements Formattable, then the method Formattable, then the method arg.formatTo() is invoked. Otherwise, the result is evaluated by invoking… Continue Reading format

Java String.lastIndexOf() The method lastIndexOf() returns the index of the last occurrence of a String in another String. If an int is passed to the method, then the method searches for the Unicode character equivalent. We can also pass the index of the character to start searching from. Available Signatures… Continue Reading last-index-of

Java String.endsWith() The method endsWith() is a convenience method that checks if a String ends with another given String. If the argument is an empty String, then the method returns true. Available Signatures [source,java,gutter:,false] public boolean endsWith(String suffix) Example [source,java,gutter:,true] @Test public void whenCallEndsWith_thenCorrect() { String s1 = “test”; assertTrue(s1.endsWith(“t”));… Continue Reading ends-with