startswith
如果字符串以指定的前缀开始,则返回 true;否则返回 false。
public class Test {
public static void main(String args[]) {
String Str = new String("www.666.com");
System.out.print("返回值 :" );
System.out.println(Str.startsWith("www") );
System.out.print("返回值 :" );
System.out.println(Str.startsWith("666") );
System.out.print("返回值 :" );
System.out.println(Str.startsWith("666", 4) );
}
}
输出
返回值 :true
返回值 :false
返回值 :true
Contains
它能够处理所有字符串数据类型(BIT、BLOB 和 CHARACTER),并返回布尔值以指示一个字符串是否包含在另一个字符串中。
String s1="abc";
String s2="def";
boolean a=s1.contains("bc");
boolean b=s2.contains("bc");
System.out.println(a);//true
System.out.println(b);//false
a包含 所以true
b不包含 所以false
containsKey
containsKey(Object key) 方法的规范中写道:“当且仅当此映射包含针对满足 (key== null ? k==null :
key.equals(k)) 的键 k 的映射关系时,返回 true”。不 应将此规范解释为:调用具有非空参数 key 的
Map.containsKey 将导致对任意的键 k 调用 key.equals(k)。实现可随意进行优化,以避免调用 equals
package com.okdi.controller;
import java.util.HashMap;
import java.util.Map;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Map map=new HashMap();
map.put("a","aaa");
System.out.println(map.containsKey("a")); //输出true 如果这个map集合中有这个key就返回true
System.out.println(map.containsKey("b")); //输出false 没有就返回false
}
}