GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Python Technologies
  • Databases
  • Computer Programming
  • Web Development
  • Java Technologies
  • Computer Science
  • Mobile Development
  • Big Data & Analytics
  • Microsoft Technologies
  • DevOps
  • Latest Technologies
  • Machine Learning
  • Digital Marketing
  • Software Quality

This view

  • Original page
  • New address

GeezerVison is showing www.tutorialspoint.com — Java StringBuffer codePointBefore() Method

java package tutorial
  • Java.lang - Home
  • Java.lang - Boolean
  • Java.lang - Byte
  • Java.lang - Character
  • Java.lang - Character.Subset
  • Java.lang - Character.UnicodeBlock
  • Java.lang - Class
  • Java.lang - ClassLoader
  • Java.lang - Compiler
  • Java.lang - Double
  • Java.lang - Enum
  • Java.lang - Float
  • Java.lang - InheritableThreadLocal
  • Java.lang - Integer
  • Java.lang - Long
  • Java.lang - Math
  • Java.lang - Number
  • Java.lang - Object
  • Java.lang - Package
  • Java.lang - Process
  • Java.lang - ProcessBuilder
  • Java.lang - Runtime
  • Java.lang - RuntimePermission
  • Java.lang - SecurityManager
  • Java.lang - Short
  • Java.lang - StackTraceElement
  • Java.lang - StrictMath
  • Java.lang - String
  • Java.lang - StringBuffer
  • Java.lang - StringBuilder
  • Java.lang - System
  • Java.lang - Thread
  • Java.lang - ThreadGroup
  • Java.lang - ThreadLocal
  • Java.lang - Throwable
  • Java.lang - Void
  • Java.lang - Interfaces
  • Java.lang - Errors
  • Java.lang - Exceptions
  • Java.lang Package Useful Resources
  • Java.lang - Useful Resources
  • Java.lang - Discussion
Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Online Resume Builder
  • HR Interview Questions
  • Computer Glossary
  • Who is Who

Java StringBuffer codePointBefore() Method



Previous
Quiz
Next

The Java StringBuffer codePointBefore() method is used to return a character (its Unicode code point) present in its preceding index of a StringBuffer. The index of a StringBuffer ranges from 1 to length().

If the char value at (index - 1) is in the low-surrogate range, (index - 2) is not negative, with its char value in the high-surrogate range, then the supplementary code point value of the surrogate pair will be the result. And if the char value at index - 1 is an unpaired low-surrogate or a high-surrogate, the method results in a surrogate value. Otherwise, the ordinary char value is returned.

Syntax

Following is the syntax for Java StringBuffer codePointBefore() method

public int codePointBefore(int index)

Parameters

  • index − This is the index following the code point that should be returned.

Return Value

This method returns the Unicode code point value before the given index.

Example: Getting a codePoint before Preceding Index

If we pass any index of a lettered CharSequence input as the argument of the method, the return value is the code point of a character present in the preceding index of a StringBuffer.

The following example shows the usage of Java StringBuffer codePointBefore() method.

package com.tutorialspoint;

public class StringBufferDemo {

   public static void main(String[] args) {

      StringBuffer buff = new StringBuffer("TUTORIALS");
      System.out.println("buffer = " + buff);

      // returns the codepoint before index 3
      int retval = buff.codePointBefore(3);
      System.out.println("Character(unicode point) = " + retval);

      buff = new StringBuffer("amrood admin ");
      System.out.println("buffer = " + buff);

      // returns the codepoint before index 6
      retval = buff.codePointBefore(6);
      System.out.println("Character(unicode point) = " + retval);
   } 
}

Output

Let us compile and run the above program, this will produce the following result −

buffer = TUTORIALS
Character(unicode point) = 84
buffer = amrood admin
Character(unicode point) = 100

Example: Getting a codePoint before Preceding Index in StringBuffer with Digits

Similarly, when we pass any index of a StringBuffer containing digits as the argument of the method, the return value is the code point of a digit character present before that index.

public class StringBufferDemo {

   public static void main(String[] args) {

      StringBuffer sb = new StringBuffer("69813601");
      System.out.println("String Buffer = " + sb);

      int result = sb.codePointBefore(5);
      System.out.println("Character(unicode point) = " + result);
   } 
}

Output

If we compile and run the given program above, the output is achieved as follows −

String Buffer = 69813601
Character(unicode point) = 51

Example: Getting a codePoint before Preceding Index in StringBuffer with Symbols

The method also returns a valid Unicode point value when we pass an index of a StringBuffer containing symbols.

public class StringBufferDemo {

   public static void main(String[] args) {

      StringBuffer sb = new StringBuffer("@#$%^&*");
      System.out.println("String Buffer = " + sb);

      int result = sb.codePointBefore(2);
      System.out.println("Character(unicode point) = " + result);
   } 
}

Output

If we compile and run the given program above, the output is achieved as follows −

String Buffer = @#$%^&*
Character(unicode point) = 35
java_lang_stringbuffer.htm
Tutorix - AI Tutor
Previous Quiz Next
Advertisements
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.