不同:
1、参数类型。setproperty方法的参数类型都只能是string的字符串类型,而put方法的参数为(object key, object value),类型是object!
2、空值。hashmap的value参数可以设置空值null,而当setproperty的value参数为null时,会抛出空指针异常nullpointerexception,反编译的class文件中是这样写的:
if (value == null) {
throw new nullpointerexception();
}
所以在使用setproperty方法时要注意捕获异常!
二者共同点在于都实现了java.util.map接口,properties.setproperty方法实际是执行的map的put方法。