ArrayList<ArrayList<Object>> a = new ArrayList<>(); // 打造这样一个数据的集合 [[1,2],[2,3]] 要求 生成字符串 [1,2]#[2,3]
for (int i = 0; i < 2; i++) {
ArrayList<Object> c = new ArrayList<>();
c.add(i+1);
c.add(i+2);
a.add(c);
//打印单个子集合的字符串形式数据
Log.i("myinfo",c.toString());
}
StringBuilder builder = new StringBuilder();
builder.append(a.get(0).toString()+"#"+a.get(1).toString());
//打印该集合的字符串形式数据
Log.i("myinfo",builder.toString());
/**
* Returns the string representation of this {@code Collection}. The presentation
* has a specific format. It is enclosed by square brackets ("[]"). Elements
* are separated by ', ' (comma and space).
*
* @return the string representation of this {@code Collection}.
*/
@Override
public String toString() {
if (isEmpty()) {
return "[]";
}
StringBuilder buffer = new StringBuilder(size() * 16);
buffer.append('[');
Iterator<?> it = iterator();
while (it.hasNext()) {
Object next = it.next();
if (next != this) {
buffer.append(next);
} else {
buffer.append("(this Collection)");
}
if (it.hasNext()) {
buffer.append(", ");
}
}
buffer.append(']');
return buffer.toString();
}
if (next != this) {
buffer.append(next);
} else {
buffer.append("(this Collection)");
}
ArrayList<ArrayList<Object>> a = new ArrayList<>();
for (int i = 0; i < 2; i++) {
ArrayList<Object> c = new ArrayList<>();
c.add(i+1);
c.add(i+2);
c.add(c);
//打印单个子集合的字符串形式数据
Log.i("myinfo",c.toString());
}
/**
* Returns a string containing a concise, human-readable description of this
* object. Subclasses are encouraged to override this method and provide an
* implementation that takes into account the object's type and data. The
* default implementation is equivalent to the following expression:
* <pre>
* getClass().getName() + '@' + Integer.toHexString(hashCode())</pre>
* <p>See <a href="{@docRoot}reference/java/lang/Object.html#writing_toString">Writing a useful
* {@code toString} method</a>
* if you intend implementing your own {@code toString} method.
*
* @return a printable representation of this object.
*/
public String toString() {
return getClass().getName() + '@' + Integer.toHexString(hashCode());
}
getClass().getName() + '@' + Integer.toHexString(hashCode())</pre>
getClass().getName()返回对象所属类的类名 hashCode()返回该对象的哈希值 Integer.toHexString(hashCode())将对象的哈希值用16进制表示
Object d = new Object();
Log.i("myinfo",d.toString());
/**
* Returns this string.
*/
@Override
public String toString() {
return this;
}
/**
* Returns the contents of this builder.
*
* @return the string representation of the data in this builder.
*/
@Override
public String toString() {
/* Note: This method is required to workaround a compiler bug
* in the RI javac (at least in 1.5.0_06) that will generate a
* reference to the non-public AbstractStringBuilder if we don't
* override it here.
*/
return super.toString();
}
/**
* Returns the current String representation.
*
* @return a String containing the characters in this instance.
*/
@Override
public String toString() {
if (count == 0) {
return "";
}
return StringFactory.newStringFromChars(0, count, value);
}
@Override
public synchronized String toString() {
return super.toString();
}
/**
* Returns the current String representation.
*
* @return a String containing the characters in this instance.
*/
@Override
public String toString() {
if (count == 0) {
return "";
}
return StringFactory.newStringFromChars(0, count, value);
}
public String toString() {
Iterator<Entry<K,V>> i = entrySet().iterator();
if (! i.hasNext())
return "{}";
StringBuilder sb = new StringBuilder();
sb.append('{');
for (;;) {
Entry<K,V> e = i.next();
K key = e.getKey();
V value = e.getValue();
sb.append(key == this ? "(this Map)" : key);
sb.append('=');
sb.append(value == this ? "(this Map)" : value);
if (! i.hasNext())
return sb.append('}').toString();
sb.append(',').append(' ');
}
}
Map<String,String> map = new HashMap<>();
map.put("keyA","valueA");
map.put("keyB","valueB");
map.put("keyC","valueC");
Log.i("myinfo",map.toString());
05-12 11:41:30.898 4490-4490/com.maiji.magkarepatient I/myinfo: {keyA=valueA, keyB=valueB, keyC=valueC}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有