码迷,mamicode.com
首页 > 其他好文 > 详细

String类的一些方法

时间:2015-09-17 21:40:45      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

  String 类有以下方法:

startsWith(String prefix)

boolean java.lang.String.startsWith(String prefix)

 

Tests if this string starts with the specified prefix.

Parameters:
prefix the prefix.
Returns:
true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise. Note also that true will be returned if the argument is an empty string or is equal to this String object as determined by the equals(Object) method.
Since:
1. 0
就是判断字符串中的后缀是否为参数prefix,如果是就返回true,如果不是就返回false。
这在安卓中可以用来识别音频文件,如mp3文件等。
对应的,还有一个方法,
endsWith(String suffix)
boolean java.lang.String.endsWith(String suffix)

Tests if this string ends with the specified suffix.

Parameters:
suffix the suffix.
Returns:
true if the character sequence represented by the argument is a suffix of the character sequence represented by this object; false otherwise. Note that the result will be true if the argument is the empty string or is equal to this String object as determined by the equals(Object) method.
可以用来判断一个字符串是否以suffix这个参数开头。

String类的一些方法

标签:

原文地址:http://www.cnblogs.com/Sunnor/p/4817613.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!