public static void main(String[] args) { Hashtable ht = new Hashtable(); ht.put("1", "123"); ht.put("2", "456"); ht.put("3", "789");
Enumeration e = ht.elements(); while (e.hasMoreElements()) { String s = e.nextElement().toString(); int len = s.length(); byte[] b = new byte[len]; for (int i = 0; i < len; i++) { b[i] = (byte)s.charAt(i); } } }此方法很笨。不过可以实现功能。 我记得好像有一个函数可以以string转成char[]数组来的。找不到了。
getBytes() 不过楼住的题目不是很明确
public static void main(String[] args) { HashMap map = new HashMap(); map.put("1","123"); map.put("2","234");
StringBuffer sb = new StringBuffer(); Iterator iter = map.keySet().iterator(); while( iter.hasNext() ) { String key = (String)iter.next(); String value = (String)map.get(key); sb.append(key); sb.append(value); } byte[] result = sb.toString().getBytes(); for(int i=0; null!=result && i<result.length; i++) { System.out.println((char)result[i]); }
Hashtable ht = new Hashtable();
ht.put("1", "123");
ht.put("2", "456");
ht.put("3", "789");
Enumeration e = ht.elements();
while (e.hasMoreElements()) {
String s = e.nextElement().toString();
int len = s.length();
byte[] b = new byte[len];
for (int i = 0; i < len; i++) {
b[i] = (byte)s.charAt(i);
}
}
}此方法很笨。不过可以实现功能。
我记得好像有一个函数可以以string转成char[]数组来的。找不到了。
{
HashMap map = new HashMap();
map.put("1","123");
map.put("2","234");
StringBuffer sb = new StringBuffer();
Iterator iter = map.keySet().iterator();
while( iter.hasNext() )
{
String key = (String)iter.next();
String value = (String)map.get(key);
sb.append(key);
sb.append(value);
}
byte[] result = sb.toString().getBytes();
for(int i=0; null!=result && i<result.length; i++)
{
System.out.println((char)result[i]);
}
}试试先,能满足要求否?