Tabnine Logo
String.chars
Code IndexAdd Tabnine to your IDE (free)

How to use
chars
method
in
java.lang.String

Best Java code snippets using java.lang.String.chars (Showing top 20 results out of 1,341)

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");
}
java.langStringchars

Popular methods of String

  • equals
  • length
    Returns the number of characters in this string.
  • substring
    Returns a string containing a subsequence of characters from this string. The returned string shares
  • startsWith
    Compares the specified string to this string, starting at the specified offset, to determine if the
  • format
    Returns a formatted string, using the supplied format and arguments, localized to the given locale.
  • split
    Splits this string using the supplied regularExpression. See Pattern#split(CharSequence,int) for an
  • trim
  • valueOf
    Creates a new string containing the specified characters in the character array. Modifying the chara
  • indexOf
  • endsWith
    Compares the specified string to this string to determine if the specified string is a suffix.
  • toLowerCase
    Converts this string to lower case, using the rules of locale.Most case mappings are unaffected by t
  • contains
    Determines if this String contains the sequence of characters in the CharSequence passed.
  • toLowerCase,
  • contains,
  • getBytes,
  • <init>,
  • equalsIgnoreCase,
  • replace,
  • isEmpty,
  • charAt,
  • hashCode,
  • lastIndexOf

Popular in Java

  • Making http requests using okhttp
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getResourceAsStream (ClassLoader)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • Socket (java.net)
    Provides a client-side TCP socket.
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now