1.Object
Object類是所有類的父類楚里,位于java.lang包中断部。如果一個(gè)類沒(méi)有用extends明確指出繼承于某個(gè)類,那么它默認(rèn)繼承Object類腻豌。
一些方法:
toString方法可以將任何一個(gè)對(duì)象轉(zhuǎn)換成字符串返回家坎,返回值的生成算法為:getClass().getName() + ‘@’ + Integer. toHexString(hashCode())
在子類中可以重寫toString方法
equals方法:
Object類中equals方法源代碼如下:
public boolean equals(Object obj)
{
return this == obj;
}
Object中的equals方法是直接判斷this和obj本身的值是否相等嘱能,即用來(lái)判斷調(diào)用equals的對(duì)象和形參obj所引用的對(duì)象是否是同一對(duì)象,所謂同一對(duì)象就是指內(nèi)存中同一塊存儲(chǔ)單元虱疏,如果this和obj指向的是同一塊內(nèi)存對(duì)象惹骂,則返回true,如果this和obj指向的不是同一塊內(nèi)存做瞪,則返回false对粪,注意:即便是內(nèi)容完全相等的兩塊不同的內(nèi)存對(duì)象,也返回false装蓬。
equals方法(equals方法不能作用于基本數(shù)據(jù)類型的變量)著拭,如果沒(méi)有對(duì)equals方法進(jìn)行重寫,則比較的是引用類型的變量所指向的對(duì)象的地址牍帚;諸如String儡遮、Date等類對(duì)equals方法進(jìn)行了重寫的,比較的是所指向的對(duì)象的內(nèi)容暗赶。
2.JSONArray
public final class JSONArray:
在包net.sf.json中鄙币,繼承自O(shè)bject,實(shí)現(xiàn)了接口JSON蹂随、List十嘿、Comparable
一些方法:
public static JSONArray fromObject(Obeject object):
Creates a JSONArray.
Inspects the object type to call the correct JSONArray factory method. Accepts JSON formatted strings, arrays, Collections and Enums.
public int size()
Get the number of elements in the JSONArray, included nulls
public Object get(String key):
Get the value object associated with a key.
3.JSONObject
public final class JSONObject:
在包net.sf.json中,繼承自O(shè)bject岳锁,實(shí)現(xiàn)了接口JSON绩衷、Map、Comparable
一些方法:
public static JSONObject fromObject(Obeject object):
Creates a JSONObject.
public Object get(String key):
Get the value object associated with a key.
public int size()
Get the number of keys stored in the JSONObject.
public String toString()
Make a JSON text of this JSONObject. For compactness, no whitespace is added. If this would not result in a syntactically correct JSON text, then null will be returned instead.
更多可參考鏈接:
http://json-lib.sourceforge.net/apidocs/jdk15/index.html