I have found the answer. Thanks for all the ideas.
One of the uses of the + line idiom "\0", especially when you see it with an a SortedSetwith a rangefinder operation , is to use it to find the
successor of the line.
, (subSet()
, headSet() tailSet()) ,
. Java Doc of Sorted Set
. , , ( ). ( ), , lowEndpoint (highEndpoint). , , s . , s , :
SortedSet sub = s.subSet(, + "\ 0" );
, :
countrySet.headSet("Japan\0");
countrySet.headSet("Japan")
, countrySet
,
"Japan" (.. );
, ,
"Japan" (.. ).
,
:
import java.util.Arrays;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
public class StringPlusNull {
public static void main(String[] args) {
List<String> countryList
= Arrays.asList("U.S.", "U.K.", "China", "Japan", "Korea");
SortedSet<String> countrySet
= new TreeSet<>(countryList);
String toElement = "Japan";
SortedSet<String> countryHeadSet
= countrySet.headSet(toElement);
System.out.format("There are %d countries in the "
+ "(half-open) headset [, %s): %s%n"
, countryHeadSet.size(), toElement, countryHeadSet);
toElement = "Japan\0";
countryHeadSet
= countrySet.headSet(toElement);
System.out.format("There are %d countries in the "
+ "(half-open) headset [, %s): %s%n"
, countryHeadSet.size(), toElement, countryHeadSet);
}
}
:
There are 1 countries in the (half-open) headset [, Japan): [China]
There are 2 countries in the (half-open) headset [, Japan ): [China, Japan]