### Convert Java Map to B4X Map

Example of converting a Java Map to a B4x Map.
Getting the list of colors from Java and return as B4x Map
Java Code
/**
* getColorMap
* @param None
* @return Map (B4A object MyMap) of Colors Name = Value
*/
public static Map.MyMap getColorMap() throws IllegalArgumentException, IllegalAccessException, ClassNotFoundException
{
Class clcolor = Class.forName("javafx.scene.paint.Color");
Map.MyMap colormap = new Map.MyMap();
if (clcolor != null) {
Field[] field = clcolor.getFields();
for (int i = 0; i < field.length; i++) {
Field f = field[i];
Object objn = f.get(null);
if(objn instanceof Color){
Color c = (Color) objn;
Map m = new Map();
m.Initialize();
m.Put(f.getName(), c.toString());
colormap.putAll(m.getObject());
}
}
}
return colormap;
}
B4x
Various examples.
Example 1
Dim m As Map = cl.ColorMap
For i = 0 To m.Size - 1
Log(m.GetKeyAt(i) & " = " & m.GetValueAt(i))
Next
Example 2
`Sub buttonColorMap_Action
Dim sb As StringBuilder
Dim rlu As GetColors
Dim m As Map = rlu.ColorMap
sb.Initialize
For i = 0 To m.Size - 1
sb.Append(m.GetKeyAt(i) & " = " & m.GetValueAt(i) & CRLF)
Next
textareaColorMap.Text = sb.ToString
End Sub`

Changed: , Category: Libraries, File: T6C214M1561.htm, ID: 1561