I want to compare two variables the first arraylist and the second is string
How can i convert the String to arrayList to compare those values in the variables
thank you in advance
Hard to understand your question, but if your String is like this "cat,dog,elephant" then you can use String.split(",") to get a String array, and then convert that to an ArrayList like this:
ArrayList<String> arrayList = new ArrayList(Arrays.asList(myString.split(",")));
Related
now i've got simple setter and getter of string array. I want to use setter to put some retrevied json info + same text to array. When i use belowe code:
met.setPlacepic(new String[]{"http://dfsdfsdfsf/" + json.getString("source")});
it looks like setter put only one string to array, despite there is many more data.
Declaration is simple
public String[] placepic
and the setter is also simple:
public void setPlacepic(String[] placepic) {
this.placepic = placepic;
}
Anybody knows reason of this?
If the number of strings is fixed (you know exactly how many element you would have in the array), then you could use String Arrays:
String[] placepic = new String[20]; //20 strings
//Then, in your loop:
placepic[i] = yourData;
If you do NOT know how many strings in your data, You should use List:
List<String> placepicList= new ArrayList<String>();
//Then, in your loop:
placepicList.add(yourData);
//Then after the loop, you get the array
String[] placepic = placepicList.toArray(new String[placepicList.size()]);
I created an arraylist of strings
List<String> textArray = new ArrayList<String>();
and then I added the strings(which I am getting from edittext) to textArray as follows
String text = editText1.getText().toString();
textArray.add(text);
Now I created a button and need to remove the string from the array when the button is clicked.But i dont know what to do.
I know for arrays of bitmaps we clear a bitmap from array using recycle but Please suggest me how to remove or clear the string from arraylist.
You can call one of:
to remove all entries
textArray.clear();
to remove from a specific position (e.g. first item)
textArray.remove(0);
to remove a specific string (that equals yours)
textArray.remove("myString");
Try this..
Getting position from the textArray array list
int pos = textArray.indexOf(text);
and then remove from the string position
textArray.remove(pos);
because we cannot directly remove the string. we can remove the string contains position.
You can do it with more then one way as per your need.
textArray.clear();
It will clear whole ArrayList.
If you want to remove only some specifis data from index then,
textArray.remove(INDEX TO REMOVE);
Try This
String text = editText1.getText().toString();
textArray.add(text);
to remove
textArray.remove(text);
I have an arraylist in which i am storing a list of values. I have to check whether the list contains the same value more than once..And i need only the non-repeating values.. How can i check the number of existences of a value in array list??
Thanks in advance..
Here is how you can do it:
ArrayList<String>numbers= new ArrayList<String>();
numbers.add("1");
numbers.add("2");
numbers.add("1");
numbers.add("3");
int count= Collections.frequency(numbers, "1");
In this way count returns 2.
use
public static int frequency(Collection c,
Object o)
to get frequency of an object in a collection(arraylist).
I have
ArrayList<String> ids = ArrayList<String>();
What would be the cleanest way to make it Parceleable? Apparently String itself is not parcelable, so Parcel.writeList(ids) is not working.
I was thinking to either parcelize ArrayList<Uri> or put array contents into a Bundle.
Convert your list to String[] and use Parcel.writeStringArray. Example here
This isnt parcelizing, but to put it in a bundle:
ArrayList<String> ids = new ArrayList<String>();
savedInstanceState.putStringArrayList("key",ids);
i want to add the current string in a textview view to a string array in arrays.xml.then display the last/previous string of that array in a textview (setText).
You cannot modify arrays.xml at runtime -- sorry! You will need to modify an in-memory ArrayList or something instead.