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

How to use
charAt
method
in
java.lang.String

Best Java code snippets using java.lang.String.charAt (Showing top 20 results out of 137,088)

origin: square/okhttp

/**
 * Returns the index of the first character in {@code input} that is {@code delimiter}. Returns
 * limit if there is no such character.
 */
public static int delimiterOffset(String input, int pos, int limit, char delimiter) {
 for (int i = pos; i < limit; i++) {
  if (input.charAt(i) == delimiter) return i;
 }
 return limit;
}
origin: square/okhttp

/**
 * Returns the index of the first character in {@code input} that contains a character in {@code
 * delimiters}. Returns limit if there is no such character.
 */
public static int delimiterOffset(String input, int pos, int limit, String delimiters) {
 for (int i = pos; i < limit; i++) {
  if (delimiters.indexOf(input.charAt(i)) != -1) return i;
 }
 return limit;
}
origin: square/okhttp

/**
 * Returns the next index in {@code input} at or after {@code pos} that contains a character from
 * {@code characters}. Returns the input length if none of the requested characters can be found.
 */
public static int skipUntil(String input, int pos, String characters) {
 for (; pos < input.length(); pos++) {
  if (characters.indexOf(input.charAt(pos)) != -1) {
   break;
  }
 }
 return pos;
}
origin: stackoverflow.com

 public static String humanReadableByteCount(long bytes, boolean si) {
  int unit = si ? 1000 : 1024;
  if (bytes < unit) return bytes + " B";
  int exp = (int) (Math.log(bytes) / Math.log(unit));
  String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
  return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
origin: square/retrofit

 @Override public Character convert(ResponseBody value) throws IOException {
  String body = value.string();
  if (body.length() != 1) {
   throw new IOException(
     "Expected body of length 1 for Character conversion but was " + body.length());
  }
  return body.charAt(0);
 }
}
origin: square/okhttp

static boolean percentEncoded(String encoded, int pos, int limit) {
 return pos + 2 < limit
   && encoded.charAt(pos) == '%'
   && decodeHexDigit(encoded.charAt(pos + 1)) != -1
   && decodeHexDigit(encoded.charAt(pos + 2)) != -1;
}
origin: google/guava

 private static String escapeAndQuote(String value) {
  StringBuilder escaped = new StringBuilder(value.length() + 16).append('"');
  for (int i = 0; i < value.length(); i++) {
   char ch = value.charAt(i);
   if (ch == '\r' || ch == '\\' || ch == '"') {
    escaped.append('\\');
   }
   escaped.append(ch);
  }
  return escaped.append('"').toString();
 }
}
origin: ReactiveX/RxJava

static int countLine(String s, int kdx) {
  int c = 1;
  for (int i = kdx; i >= 0; i--) {
    if (s.charAt(i) == '\n') {
      c++;
    }
  }
  return c;
}
origin: square/okhttp

static void checkValue(String value, String name) {
 if (value == null) throw new NullPointerException("value for name " + name + " == null");
 for (int i = 0, length = value.length(); i < length; i++) {
  char c = value.charAt(i);
  if ((c <= '\u001f' && c != '\t') || c >= '\u007f') {
   throw new IllegalArgumentException(Util.format(
     "Unexpected char %#04x at %d in %s value: %s", (int) c, i, name, value));
  }
 }
}
origin: square/okhttp

private static boolean pathMatch(HttpUrl url, String path) {
 String urlPath = url.encodedPath();
 if (urlPath.equals(path)) {
  return true; // As in '/foo' matching '/foo'.
 }
 if (urlPath.startsWith(path)) {
  if (path.endsWith("/")) return true; // As in '/' matching '/foo'.
  if (urlPath.charAt(path.length()) == '/') return true; // As in '/foo' matching '/foo/bar'.
 }
 return false;
}
origin: square/okhttp

private static boolean domainMatch(String urlHost, String domain) {
 if (urlHost.equals(domain)) {
  return true; // As in 'example.com' matching 'example.com'.
 }
 if (urlHost.endsWith(domain)
   && urlHost.charAt(urlHost.length() - domain.length() - 1) == '.'
   && !verifyAsIpAddress(urlHost)) {
  return true; // As in 'example.com' matching 'www.example.com'.
 }
 return false;
}
origin: square/okhttp

static void checkName(String name) {
 if (name == null) throw new NullPointerException("name == null");
 if (name.isEmpty()) throw new IllegalArgumentException("name is empty");
 for (int i = 0, length = name.length(); i < length; i++) {
  char c = name.charAt(i);
  if (c <= '\u0020' || c >= '\u007f') {
   throw new IllegalArgumentException(Util.format(
     "Unexpected char %#04x at %d in header name: %s", (int) c, i, name));
  }
 }
}
origin: google/guava

 @Override
 public Character apply(String string) {
  return string.charAt(index);
 }
}
origin: google/guava

 @Override
 public Character apply(String input) {
  return input == null ? null : input.charAt(0);
 }
};
origin: google/guava

/**
 * Writes a {@code String} as specified by {@link DataOutputStream#writeChars(String)}, except
 * each character is written using little-endian byte order.
 *
 * @throws IOException if an I/O error occurs
 */
@Override
public void writeChars(String s) throws IOException {
 for (int i = 0; i < s.length(); i++) {
  writeChar(s.charAt(i));
 }
}
origin: google/guava

@Override
public String escape(String s) {
 int slen = s.length();
 for (int index = 0; index < slen; index++) {
  char c = s.charAt(index);
  if (c < replacements.length && replacements[c] != null) {
   return escapeSlow(s, index);
  }
 }
 return s;
}
origin: google/guava

 /** Helper to manually escape a 7-bit ascii character */
 private String escapeAscii(char c) {
  Preconditions.checkArgument(c < 128);
  String hex = "0123456789ABCDEF";
  return "%" + hex.charAt((c >> 4) & 0xf) + hex.charAt(c & 0xf);
 }
}
origin: google/guava

 private static String firstCharOnlyToUpper(String word) {
  return word.isEmpty()
    ? word
    : Ascii.toUpperCase(word.charAt(0)) + Ascii.toLowerCase(word.substring(1));
 }
}
origin: google/guava

 @Override
 public boolean apply(String input) {
  return asList('a', 'e', 'i', 'o', 'u').contains(input.charAt(0));
 }
};
origin: google/guava

public void testSkipFully() throws IOException {
 String testString = "abcdef";
 Reader reader = new StringReader(testString);
 assertEquals(testString.charAt(0), reader.read());
 CharStreams.skipFully(reader, 1);
 assertEquals(testString.charAt(2), reader.read());
 CharStreams.skipFully(reader, 2);
 assertEquals(testString.charAt(5), reader.read());
 assertEquals(-1, reader.read());
}
java.langStringcharAt

Javadoc

Returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.

If the char value specified by the index is a surrogate, the surrogate value is returned.

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,
  • hashCode,
  • lastIndexOf

Popular in Java

  • Finding current android device location
  • onCreateOptionsMenu (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • JComboBox (javax.swing)
  • Join (org.hibernate.mapping)
  • From CI to AI: The AI layer in your organization
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