Monday, February 25, 2019

String concat() in java with example

String concat() method in java with example:

concat() method is present in the java.lang.String class. concat() method concatenate the given string at a time. This method concatenates the specified string to the end of this string and returns a new string with the new value. This mehtod can be used to concatenate multiple strings one by one. This method can be called multiple times on the string.

Syntax:

public String concat​(String str)


Return value: String


String concat() in java with example


A string that represents the concatenation of this object's characters followed by the string argument's characters.

In Java 8, a new method join() is introduced. String join() method example to concatenate the given string with a delimiter.

Friday, February 22, 2019

Java String compareToIgnoreCase​ method example - Internal Implementation

String compareToIgnoreCase​ method in java with example:

compareToIgnoreCase​() method compares two strings lexicographically by comparing the each character in both strings and ignoring case differences. 

This method returns an integer whose sign is that of calling compareTo with normalized versions of the strings where case differences have been eliminated by calling Character.toLowerCase(Character.toUpperCase(character)) on each character. 



String compareToIgnoreCase​()


Syntax:

Here is the syntax of this method.


public int compareToIgnoreCase​(String str)

Thursday, February 21, 2019

String codePointAt() method in java with example - Internal Implementation

String codePointAt() in Java:

The codePointAt(int index) method of String class takes an index as a parameter and returns a character unicode point at that index in String contained by String or we can say charPointAt() method returns the “unicode number” of the character at that index. The index refers to char values (Unicode code units) and the value of index must be lie between 0 to length-1.

If the char value present at the given index lies in the high-surrogate range, the following index is less than the length of this sequence, and the char value at the following index is in the low-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned. Otherwise, the char value at the given index is returned.


String codePointAt


Syntax:


public int codePointAt​(int index)

Tuesday, February 19, 2019

Java 9 String chars() method example - Internal Implementation

Java String chars():


chars method is introduced in package java.lang.String class from Java 9 onwards. This method returns a stream of int zero-extending the char values from this sequence. Any char which maps to a surrogate code point is passed through uninterpreted. If the sequence is mutated while the stream is being read, the result is undefined.


Java String chars() method example



Syntax:

public IntStream chars​()


This method returns IntStream which holds of characters of input string and will have some light performance penalty.