html:optionsCollection property="formIdNameMap" value="key" label="value"
Thursday, June 5, 2008
Struts : DropDown Population With HashMap
The Below line of code will usefull to Load the values from the HashMap to the DropDow / List box.
Wednesday, June 4, 2008
Java : HashMap to StringArray
This below code helps you to Convert the HashMap Values / Keys to StringArray, This will make your code more compact.
import java.util.HashMap;
public static void main(String str[])
{
HashMap hMap = new HashMap();
hMap.put("1","One");
hMap.put("2","Two");
String strArray[] = null;
// converting the Values's to String Array
strArray = (String[])(hMap.values().toArray(new String[0]));
System.out.println( strArray[0] + strArray[1]);
// converting the Key's to String Array
strArray = (String[])(hMap.keySet().toArray(new String[0]));
System.out.println( strArray[0] + strArray[1]);
}
import java.util.HashMap;
public static void main(String str[])
{
HashMap hMap = new HashMap();
hMap.put("1","One");
hMap.put("2","Two");
String strArray[] = null;
// converting the Values's to String Array
strArray = (String[])(hMap.values().toArray(new String[0]));
System.out.println( strArray[0] + strArray[1]);
// converting the Key's to String Array
strArray = (String[])(hMap.keySet().toArray(new String[0]));
System.out.println( strArray[0] + strArray[1]);
}
Subscribe to:
Posts (Atom)