Posts

Showing posts from February, 2017

Convert Collection to Array

1. Convert Set to Array of String           final HashMap<String, String> orderingOptionMap = new HashMap<String, String>();          orderingOptionMap.put("1", "Name: A-Z");          orderingOptionMap.put("2", "Name: Z-A");          orderingOptionMap.put("3", "Age: Ascending");          orderingOptionMap.put("4", "Age: Descending");          String[] orderingOption =   orderingOptionMap.keySet().toArray(new String[orderingOptionMap.size()]);           

String constant java class(created- StringConstant.java) vs string resource (strings.xml)?

Below are few points to consider before defining any string in any of the file- 1. Organize based on what makes sense!     Like, put string constants that highlights database connection credentials, table name, column name or any internal used constant in Java class where else the strings that are displayed to the user should go into strings.xml file. In short, strings.xml holds DISPLAY strings. 2. Constant declared in strings.xml file will be available only to context. Hence, whenever you want to use them make sure you have context to access them. Like in Adapters.