Here you can find the source of startsWith(String s, char c)
Parameter | Description |
---|---|
s | The string to check. Can be <jk>null</jk>. |
c | The character to check for. |
public static boolean startsWith(String s, char c)
//package com.java2s; // * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * public class Main { /**/*w w w . java 2 s .c o m*/ * An efficient method for checking if a string starts with a character. * * @param s The string to check. Can be <jk>null</jk>. * @param c The character to check for. * @return <jk>true</jk> if the specified string is not <jk>null</jk> and starts with the specified character. */ public static boolean startsWith(String s, char c) { if (s != null) { int i = s.length(); if (i > 0) return s.charAt(0) == c; } return false; } /** * Returns the character at the specified index in the string without throwing exceptions. * * @param s The string. * @param i The index position. * @return The character at the specified index, or <code>0</code> if the index is out-of-range or the string * is <jk>null</jk>. */ public static char charAt(String s, int i) { if (s == null) return 0; if (i < 0 || i >= s.length()) return 0; return s.charAt(i); } }