volcano_Secret volcano_Secret - 1 month ago 12
Android Question

How to convert multiple string into arraylist?

I m new in android.I want to add these String variables to ArrayList, what I am doing now.
Suppose I have a four of String Variables.....

String number = "9876543211";
String type = "incoming";
String date = "1/1/2016";
String duration = "45 sec";


Here is my java code.......

while (managedCursor.moveToNext()) {
String number = managedCursor.getString(number1);
String type2 = managedCursor.getString(type1);
String date = managedCursor.getString(managedCursor.getColumnIndexOrThrow("date")).toString();
java.util.Date date1 = new java.util.Date(Long.valueOf(date));
String duration = managedCursor.getString(duration1);
String type = null;

String fDate = date1.toString();

int callcode = Integer.parseInt(type2);

sb.append("\nPhone Number:--- " + number + "");
sb.append(" \nCall Type:--- " + type + " ");
sb.append("\nCall Date:--- " + fDate + "");
sb.append("\nCall duration in sec :--- " + duration);
sb.append("\n----------------------------------");
}

Answer

Create an instance of ArrayList of type String and add the strings to them.

ArrayList<String> stringList = new ArrayList<>();
stringList.add(number);
stringList.add(type);
stringList.add(date);
stringList.add(duration);
Comments