1、判断对象类型的方法?
instanceof
2、根据程序写结果 (F:false,T:true)
public class Main {
public static void main(String []args){
String a="str"+"ing";
String b="str".concat("ing");
String c=new String("string");
String d="string";
String e="str";
String g="ing";
String h=e+g;//创建了新对象
System.out.println("a==b: "+(a==b));//F
System.out.println("a==c: "+(a==c));//F
System.out.println("a==d: "+(a==d));//T
System.out.println("a==h: "+(a==h));//F
System.out.println("b==c: "+(b==c));//F
System.out.println("b==d: "+(b==d));//F
System.out.println("b==h: "+(b==h));//F
System.out.println("c==d: "+(c==d));//F
System.out.println("c==h: "+(c==h));//F
System.out.println("d==h: "+(d==h));//F
}
}
3、ArrayList与Vector的区别?
1、Vector的方法是同步的,ArrayList不是同步的,后者性能比前者好
2、当元素超过初始大小时,Vector将其容量翻倍,而ArrayList只增加50%的容量。
4、实现StringUtil的isEmpty方法?
public static boolean isEmpty(CharSequence str) {
if (str == null || str.length() == 0)
return true;
else return false;
}
5、collection和collections区别?
Collection是一个集合接口。它提供了对集合对象进行基本操作的通用接口方法,其接口在类库中有很多具体的实现。
Collections是一个包装类。它包含有各种有关集合操作的静态多态方法。