CollationElementIterator tertiaryOrder() method in Java with Examples

2025年5月3日 | 阅读3分钟

java.text.CollationElementIterator 类有一个 tertiaryOrder() 方法。CollationElementIterator 对象的每个排序元素(collation element)的第三级(tertiary)分量由 CollationElementIterator 类提供。

语法

参数:方法需要发现一个排序元素(collation element)的第三级分量,该元素以一个整数参数的形式提供。

返回值: 该方法返回特定排序元素(Collision element)的第三级分量。

示例 1

Java代码使用 CollationElementIterator 和 RuleBasedCollator 来遍历和检查文本 "Hello Welcome To World" 的排序元素。通过使用 CollationElementIterator 遍历字符串的排序元素,并通过 RuleBasedCollator 对象提供面向区域设置的比较规则。在每次迭代中,当 next() 收集下一个排序元素后,tertiaryOrder() 方法会获取该元素的第三级分量,该分量与重音和大小写敏感性有关。程序能够输出每个元素的第三级顺序,有助于在执行复杂的基于区域设置的排序过程时进行深入的字符串比较。

实施

文件名: TertiaryOrderExample1.java

输出

 
The tertiary order for the element is 1
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 1
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 1
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 1
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0   

示例 2

此 Java 代码演示了使用 RuleBasedCollator 和 CollationElementIterator 对字符串 "Hello 123 World" 的排序元素进行的分析。RuleBasedCollator 用于面向区域设置的字符串比较,而 CollationElementIterator 则遍历字符串,将其划分为与字符对应的排序元素。在 next() 方法检索出每个元素后,tertiaryOrder() 函数用于提取第三级分量,该分量侧重于大小写和重音符号等差异。每个元素的第三级顺序都会被打印出来,从而提供对在区分排序的环境中如何处理每个字符(包括数字和字母)的全面理解。

实施

文件名: tertiaryOrderExample2.java

输出

 
The tertiary order for the element is 1
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 1
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0
The tertiary order for the element is 0   

下一主题Java XOR