java.text.BreakIterator类的previous()方法用于获取当前边界后面的前一个边界的索引(通过调用current()方法检索边界)。它提供了由BreakIterator指向的当前边界之前的第一个边界字符的偏移量。

用法:

public abstract int previous()

参数:此方法不接受任何参数。

返回值:此方法提供当前边界之后的前一个边界的索引。

下面是说明previous()方法的示例:

示例1:

// Java program to demonstrate previous() method

import java.text.*;

import java.util.*;

import java.io.*;

public class GFG {

public static void main(String[] argv)

{

// creating and initializing with zero

int current = 0, next = 0;

// creating and initializing BreakIterator

BreakIterator wb

= BreakIterator.getWordInstance();

// setting text for BreakIterator

wb.setText("Code  Geeks");

// setting the current position to index 11

// By skipping 3 boundaries

wb.next(3);

// getting the current text boundary

current = wb.current();

// display the result

System.out.println(

"current position before"

+ " calling previous() : "

+ current);

// calling previous() method

next = wb.previous();

// display the result

System.out.println(

"\ncurrent position after"

+ " calling 1st previous() : "

+ next);

// calling previous() method

next = wb.previous();

// display the result

System.out.println(

"\ncurrent position after"

+ " calling 2nd previous() : "

+ next);

}

}

输出:

current position before calling previous() : 11

current position after calling 1st previous() : 6

current position after calling 2nd previous() : 4

示例2:

// Java program to demonstrate

// previous() method

import java.text.*;

import java.util.*;

import java.io.*;

public class GFG {

public static void main(String[] argv)

{

// creating and initializing with zero

int current = 0, next = 0;

// creating and initializing BreakIterator

BreakIterator wb

= BreakIterator.getWordInstance();

// setting text for BreakIterator

wb.setText("GeeksForGeeks");

// setting the current position to index 11

// By skipping 3 boundaries

wb.next(3);

// getting the current text boundary

current = wb.current();

// display the result

System.out.println(

"current position before"

+ " calling previous() : "

+ current);

// calling previous() method

next = wb.previous();

// display the result

System.out.println(

"\ncurrent position after"

+ " calling 1st previous() : "

+ next);

// calling previous() method

next = wb.previous();

// display the result

System.out.println(

"\ncurrent position after"

+ " calling 2nd previous() : "

+ next);

}

}

输出:

current position before calling previous() : 13

current position after calling 1st previous() : 0

current position after calling 2nd previous() : -1

java previous_Java BreakIterator previous()用法及代码示例相关推荐

  1. java break(),Java BreakIterator last()用法及代码示例

    java.text.BreakIterator类的last()方法用于获取最后一个边界的索引.它总是返回最后一个边界的最后一个字符的偏移量. 用法: public abstract int last( ...

  2. java中skip的用法,Java PushbackReader skip(long)用法及代码示例

    Java中的PushbackReader类的skip(long)方法用于跳过流中指定数量的字符.此字符数被指定为参数.如果通过跳过到达流的末尾,它将阻塞流,直到它获得一些字符或抛出IOExceptio ...

  3. java sliplist_Java List retainAll()用法及代码示例

    此方法用于将指定集合中存在于集合中的所有元素保留到列表中. 用法: boolean retainAll(Collection c) 参数:此方法只有一个参数,即要在给定列表中保留哪些元素的集合. 返回 ...

  4. java lazy_Java AtomicLong lazySet()用法及代码示例

    Java.util.concurrent.atomic.AtomicLong.lazySet()是Java中的内置方法,可更新先前的值并将其设置为在参数中传递的新值. 用法: public final ...

  5. java doublebuffer_Java DoubleBuffer clear()用法及代码示例

    java.nio.CharBuffer类的clear()方法用于清除此缓冲区.在清除此缓冲区时,需要进行以下更改: 位置设置为零 限制设置为容量 商标被丢弃. 用法: public final Dou ...

  6. java filesystem_Java FileSystem isReadOnly()用法及代码示例

    FileSystem类的isReadOnly()方法用于检查此文件系统是否仅允许对其文件存储区进行只读访问.如果文件系统仅允许对其文件存储进行读取访问,则此方法将返回true,否则返回false. 用 ...

  7. java bidi_Java Bidi createLineBidi()用法及代码示例

    java.text.Bidi类的createLineBidi()方法用于创建具有相同基本方向并表示该范围内当前bidi的每个属性的新的bidi对象. 用法: public Bidi createLin ...

  8. java intfilter_Java IntStream filter()用法及代码示例

    IntStream filter(IntPredicate predicate)返回一个由与给定谓词匹配的流元素组成的流.这是一个中间操作.这些操作总是很懒惰,即执行诸如filter()之类的中间操作 ...

  9. java seconds_Java LocalTime minusSeconds()用法及代码示例

    LocalTime类的minusSeconds()方法用于从此LocalTime中减去指定的秒数,然后将结果作为LocalTime对象返回.这一瞬间是一成不变的.计算大约在午夜结束. 用法: publ ...

最新文章

  1. 图解Oracle备份方式分类
  2. 把视频玩出花的快手来到CVPR ,解密背后AI能力,落地空间有多大?
  3. python入门教程共四本书籍-关于 Python 的经典入门书籍有哪些?
  4. HDU 5861 Road 线段树区间更新单点查询
  5. Android 近百个项目的源代码,覆盖Android开发的每个领域
  6. PHP中文获取拼音函数
  7. 排序算法 —— 选择排序
  8. devexpress textedit调整文字何文本框的间距_手把手教学:用PPT做效果超赞的文字效果...
  9. python sqlite
  10. KEIL MDK access violation at 0x40021000 : no ‘read‘ permission的一种解决方法
  11. 如何搭建测试平台?理清思路很重要
  12. Word 制作三线表
  13. Java中的反射与JDK动态代理
  14. 人肉搜索将被禁止,大家要保护好自己的个人信息!
  15. 界面设计配色方案说明图一(含RGB配色表)
  16. JupyterNotebook关闭时报Python.exe应用程序错误
  17. 程序设计思想与方法 笔记
  18. 【网络】VLAN 及其配置详解
  19. php-java-net-python-爱心公益网站()计算机毕业设计程序
  20. word文件图标无法显示的问题

热门文章

  1. 2018 Intellij IDEA 最新旗舰版注册激活破解
  2. [LoadRunner]LR性能测试结果样例分析
  3. 十六、MDT 2013 Update 1批量部署-应用程序导入及自动安装(含OFFICE 2007安装)
  4. 【WEB安全】PHP靶场实战分析——DVWA
  5. springboot在项目启动时加载字典表数据进map内存,真实测试通过。
  6. 如何设置鼠标”的速度、滚动方向等配置?
  7. win8.1安装vs2015专业版 KB2919335
  8. Hadoop自动化安装脚本
  9. 短视频App源码:如何搭建短视频社区
  10. 精彩推荐 | 金秋十月不容错过的技术演讲(上)