Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs
    • SQL FAQ’s

Java codePointBefore Method

by suresh

The Java codePointBefore method is one of the Java String Methods, which is to return the Unicode of the Character before the specified index position.

In this article, we will show how to use codePointBefore method in Java Programming language with an example. The index position of the codePointBefore Function will start from 0, Not 1.

Java codePointBefore method syntax

The basic syntax of the codePointBefore in Java Programming language is as shown below.

public int codePointBefore(int Index_Position) 

//In order to use in program
String_Object.codePointBefore(int Index_Position)
  • String_Object: Please specify the valid String Object.
  • Index_Position: Please specify the index position of the desired character.

Return Value

The Java codePointBefore Function will return the Unicode value of a Character from String_Object at specified Index_Position minus 1.

For example, if we specify codePointBefore(5), it will return the Unicode value of the character at index position 4. If we specify the Index position out of range or negative value, then the codePointBefore Function will throw an error.

TIP: Please refer ASCII Table to check the character codes of every character.

Java codePointBefore Example

In this Java program, We are going to use the Java string codePointBefore method to return the Unicode value of a Character at a specified index position minus 1.

package StringFunctions;

public class CodePointBefore {
	public static void main(String[] args) {
		String str = "Learn Free Java Tutorial";
		
		int a = str.codePointBefore(1);
		int b = str.codePointBefore(11);
		int c = str.codePointBefore(22);
		int d = str.codePointBefore(str.length()- 1);
		
		System.out.println( "Unicode Vlaue of Character at Index position 0 = " + a);
		System.out.println( "Unicode Vlaue of Character at Index position 10 = " + b);
		System.out.println( "Unicode Vlaue of Character at Index position 21 = " + c);
		System.out.println( "Unicode Vlaue of Character at Last Index position - 1 = " + d);
	}
}

OUTPUT

Java codePointBefore Method 1

ANALYSIS

Within this Java codePointBefore method example, we declared the String variable and assigned a value using the following statement

String str = "Learn Free Java Tutorial";

The following codePointBefore String Method statements will find the Character at index position 0, 10, 21. Then assign the Unicode values of those characters to the integer variables a, b, and c.

int a = str.codePointBefore(1);
int b = str.codePointBefore(11);
int c = str.codePointBefore(22);

If you observe the above screenshot, str.codePointAt(11) is returning 32. It is because we all know that character at index position 10 is Empty Space, and according to ASCII Table, the Unicode value of Empty Space is 32.

NOTE: You should count the space as One Character.

In the next line, we are using the string length function along with Java codePointBefore to calculate the string length.

int d = str.codePointBefore(str.length()- 1);

From the above code snippet, we are subtracting one from string length. Because the length of a string will count from 1 to n where the index position will start from 0 and end’s at n – 1.

The following Java System.out.println statements will print the output.

System.out.println( "Unicode Vlaue of Character at Index position 0 = " + a);
System.out.println( "Unicode Vlaue of Character at Index position 10 = " + b);
System.out.println( "Unicode Vlaue of Character at Index position 21 = " + c);
System.out.println( "Unicode Vlaue of Character at Last Index position - 1 = " + d);

Placed Under: Java

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy