Here you can find the source of endsWith(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 endsWith(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 { /**//from w w w . ja va 2s. c o m * An efficient method for checking if a string ends 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 ends with the specified character. */ public static boolean endsWith(String s, char c) { if (s != null) { int i = s.length(); if (i > 0) return s.charAt(i - 1) == 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); } }