本文整理了Java中java.lang.String.chars()
方法的一些代码示例,展示了String.chars()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。String.chars()
方法的具体详情如下:
包路径:java.lang.String
类名称:String
方法名:chars
暂无
代码示例来源:origin: SonarSource/sonarqube
private static int computeWidth(String text) {
return text.chars()
.mapToObj(i -> (char) i)
.mapToInt(c -> {
Integer length = CHAR_LENGTH.get(c);
checkState(length != null, "Invalid character '%s'", c);
return length;
})
.sum();
}
代码示例来源:origin: prestodb/presto
private static boolean validateName(String name)
{
return name.chars().noneMatch(c -> c == '<' || c == '>' || c == ',');
}
代码示例来源:origin: prestodb/presto
private static boolean validateName(String name)
{
return name.chars().noneMatch(c -> c == '<' || c == '>' || c == ',');
}
代码示例来源:origin: JanusGraph/janusgraph
public static String launder(String input) {
Preconditions.checkNotNull(input);
final StringBuilder sb = new StringBuilder();
input.chars().forEach(c -> sb.append((char) Integer.valueOf(c).intValue()));
return sb.toString();
}
代码示例来源:origin: alibaba/jetcache
private void printSepLine(StringBuilder sb, String title) {
title.chars().forEach((c) -> {
if (c == '|') {
sb.append('+');
} else {
sb.append('-');
}
});
sb.append('\n');
}
代码示例来源:origin: shekhargulati/strman-java
/**
* Counts the number of occurrences of each character in the string
*
* @param input The input string
* @return A map containing the number of occurrences of each character in the string
*/
public static Map<Character, Long> charsCount(String input) {
if (isNullOrEmpty(input)) {
return Collections.emptyMap();
}
return input.chars().mapToObj(c -> (char) c).collect(groupingBy(identity(), counting()));
}
代码示例来源:origin: google/error-prone
private boolean isProbablyType(String name) {
Symbol typeSymbol = FindIdentifiers.findIdent(name, state, KindSelector.TYP);
return typeSymbol instanceof TypeSymbol
|| name.chars().filter(c -> c == '.').count() >= 3
|| name.contains("#");
}
代码示例来源:origin: Vedenin/useful-java-links
@Benchmark
public long java8() {
// Using Java8
return testString.chars().filter(ch -> ch =='.').count();
}
代码示例来源:origin: Vedenin/useful-java-links
@Benchmark
public long java8() {
// Using Java8
return testString.chars().filter(ch -> ch =='.').count();
}
代码示例来源:origin: org.apache.ant/ant
/**
* Add a single object into the script context.
*
* @param key the name in the context this object is to stored under.
* @param bean the object to be stored in the script context.
*/
public void addBean(String key, Object bean) {
if (!key.isEmpty() && Character.isJavaIdentifierStart(key.charAt(0))
&& key.chars().skip(1).allMatch(Character::isJavaIdentifierPart)) {
beans.put(key, bean);
}
}
代码示例来源:origin: spring-projects/spring-security
private static boolean isErrorUriValid(String errorUri) {
return errorUri == null ||
errorUri.chars().allMatch(c ->
c == 0x21 ||
withinTheRangeOf(c, 0x23, 0x5B) ||
withinTheRangeOf(c, 0x5D, 0x7E));
}
代码示例来源:origin: SonarSource/sonarqube
private String randomizeCase(String s) {
return s.chars()
.map(c -> random.nextBoolean() ? Character.toUpperCase(c) : Character.toLowerCase(c))
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
.toString();
}
代码示例来源:origin: spring-projects/spring-security
private static boolean validateScope(String scope) {
return scope == null ||
scope.chars().allMatch(c ->
withinTheRangeOf(c, 0x21, 0x21) ||
withinTheRangeOf(c, 0x23, 0x5B) ||
withinTheRangeOf(c, 0x5D, 0x7E));
}
代码示例来源:origin: spring-projects/spring-security
private static boolean isScopeValid(String scope) {
return scope == null ||
scope.chars().allMatch(c ->
withinTheRangeOf(c, 0x20, 0x21) ||
withinTheRangeOf(c, 0x23, 0x5B) ||
withinTheRangeOf(c, 0x5D, 0x7E));
}
代码示例来源:origin: spring-projects/spring-security
private static boolean isDescriptionValid(String description) {
return description == null ||
description.chars().allMatch(c ->
withinTheRangeOf(c, 0x20, 0x21) ||
withinTheRangeOf(c, 0x23, 0x5B) ||
withinTheRangeOf(c, 0x5D, 0x7E));
}
代码示例来源:origin: spring-projects/spring-security
private static boolean isErrorCodeValid(String errorCode) {
return errorCode.chars().allMatch(c ->
withinTheRangeOf(c, 0x20, 0x21) ||
withinTheRangeOf(c, 0x23, 0x5B) ||
withinTheRangeOf(c, 0x5D, 0x7E));
}
代码示例来源:origin: neo4j/neo4j
@Test
public void nextAlphaNumericString()
{
Set<Integer> seenDigits = "ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789".chars().boxed()
.collect( Collectors.toSet() );
for ( int i = 0; i < ITERATIONS; i++ )
{
TextValue textValue = randomValues.nextAlphaNumericTextValue( 10, 20 );
String asString = textValue.stringValue();
for ( int j = 0; j < asString.length(); j++ )
{
int ch = asString.charAt( j );
assertTrue( "Not a character nor letter: " + ch,
Character.isAlphabetic( ch ) || Character.isDigit( ch ) );
seenDigits.remove( ch );
}
}
assertThat( seenDigits, empty() );
}
代码示例来源:origin: google/guava
public void testFlatteningToImmutableListMultimap() {
Collector<String, ?, ImmutableListMultimap<Character, Character>> collector =
ImmutableListMultimap.flatteningToImmutableListMultimap(
str -> str.charAt(0), str -> str.substring(1).chars().mapToObj(c -> (char) c));
BiPredicate<Multimap<?, ?>, Multimap<?, ?>> equivalence =
Equivalence.equals()
.onResultOf((Multimap<?, ?> mm) -> ImmutableList.copyOf(mm.asMap().entrySet()))
.and(Equivalence.equals());
ImmutableListMultimap<Character, Character> empty = ImmutableListMultimap.of();
ImmutableListMultimap<Character, Character> filled =
ImmutableListMultimap.<Character, Character>builder()
.putAll('b', Arrays.asList('a', 'n', 'a', 'n', 'a'))
.putAll('a', Arrays.asList('p', 'p', 'l', 'e'))
.putAll('c', Arrays.asList('a', 'r', 'r', 'o', 't'))
.putAll('a', Arrays.asList('s', 'p', 'a', 'r', 'a', 'g', 'u', 's'))
.putAll('c', Arrays.asList('h', 'e', 'r', 'r', 'y'))
.build();
CollectorTester.of(collector, equivalence)
.expectCollects(empty)
.expectCollects(filled, "banana", "apple", "carrot", "asparagus", "cherry");
}
代码示例来源:origin: google/guava
public void testFlatteningToImmutableSetMultimap() {
Collector<String, ?, ImmutableSetMultimap<Character, Character>> collector =
ImmutableSetMultimap.flatteningToImmutableSetMultimap(
str -> str.charAt(0), str -> str.substring(1).chars().mapToObj(c -> (char) c));
BiPredicate<Multimap<?, ?>, Multimap<?, ?>> equivalence =
Equivalence.equals()
.onResultOf((Multimap<?, ?> mm) -> ImmutableList.copyOf(mm.asMap().entrySet()))
.and(Equivalence.equals());
ImmutableSetMultimap<Character, Character> empty = ImmutableSetMultimap.of();
ImmutableSetMultimap<Character, Character> filled =
ImmutableSetMultimap.<Character, Character>builder()
.putAll('b', Arrays.asList('a', 'n', 'a', 'n', 'a'))
.putAll('a', Arrays.asList('p', 'p', 'l', 'e'))
.putAll('c', Arrays.asList('a', 'r', 'r', 'o', 't'))
.putAll('a', Arrays.asList('s', 'p', 'a', 'r', 'a', 'g', 'u', 's'))
.putAll('c', Arrays.asList('h', 'e', 'r', 'r', 'y'))
.build();
CollectorTester.of(collector, equivalence)
.expectCollects(empty)
.expectCollects(filled, "banana", "apple", "carrot", "asparagus", "cherry");
}
代码示例来源:origin: google/guava
public void testFlatteningToMultimap() {
Collector<String, ?, ListMultimap<Character, Character>> collector =
Multimaps.flatteningToMultimap(
str -> str.charAt(0),
str -> str.substring(1).chars().mapToObj(c -> (char) c),
MultimapBuilder.linkedHashKeys().arrayListValues()::build);
BiPredicate<Multimap<?, ?>, Multimap<?, ?>> equivalence =
Equivalence.equals()
.onResultOf((Multimap<?, ?> mm) -> ImmutableList.copyOf(mm.asMap().entrySet()))
.and(Equivalence.equals());
ListMultimap<Character, Character> empty =
MultimapBuilder.linkedHashKeys().arrayListValues().build();
ListMultimap<Character, Character> filled =
MultimapBuilder.linkedHashKeys().arrayListValues().build();
filled.putAll('b', Arrays.asList('a', 'n', 'a', 'n', 'a'));
filled.putAll('a', Arrays.asList('p', 'p', 'l', 'e'));
filled.putAll('c', Arrays.asList('a', 'r', 'r', 'o', 't'));
filled.putAll('a', Arrays.asList('s', 'p', 'a', 'r', 'a', 'g', 'u', 's'));
filled.putAll('c', Arrays.asList('h', 'e', 'r', 'r', 'y'));
CollectorTester.of(collector, equivalence)
.expectCollects(empty)
.expectCollects(filled, "banana", "apple", "carrot", "asparagus", "cherry");
}
内容来源于网络,如有侵权,请联系作者删除!