removing an element from String array in android
android, arrays, java, string
Solution
its better to use arraylist
arr_fav = {"1","2","3"};
List<String> numlist = new ArrayList<String>();
for(int i= 0;i<arr_fav.length;i++)
{
if(current_id == Integer.parseInt(arr_fav[i]))
{
// No operation here
}
else
{
numlist.add(arr_fav[i]);
}
}
arr_fav = numlist .toArray(new String[numlist .size()]);
Problem
Am doing a simple android application.In that I am deleting an element from array using the following code. ``` arr_fav = {"1","2","3"}; for(int i= 0;i<arr_fav.length;i++) { if(current_id == Integer.parseInt(arr_fav[i])) { arr_fav[1] = null; } } ``` By doing this am getting the array like arr_fav = {"1",null,"3"}.But I want like arr_fav = {"1","3"}.How to delete an element.Am new to this android development.Please help me to solve this.