Write a Java program to get the character (Unicode code point) before the specified index within the String.

Java Programming Language String in java (Article) String in java (Program)

1399

Program:

public class Exercise2 {

   public static void main(String[] args) {

    String str = "atnyla.com";
    System.out.println("Original String : " + str);

    // codepoint before index 1
    int val1 = str.codePointBefore(1);

   // codepoint before index 9
    int val2 = str.codePointBefore(9);

    // prints character before index1 in string
    System.out.println("Character(unicode point) = " + val1);
    // prints character before index9 in string
    System.out.println("Character(unicode point) = " + val2);
  }
}

Output:

Original String : atnyla.com
Character(unicode point) = 97
Character(unicode point) = 111
Press any key to continue . . .

Explanation:

None

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.