Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get item positions in string array android?

Let's say I have an array like this:

String[] = {
    "#abc #def",
    "#abc",
    "#def",
    "#xyz #def"
}

My question is I want to search for specific character or string like "#abc" or "a" and get their positions in the array.

like image 688
Lukas Anda Avatar asked Sep 15 '25 11:09

Lukas Anda


1 Answers

Just loop through it and check each string yourself

for(int i=0; i < array.length; i++)
    if(array[i].contains("#abc"))
        aPosition = i;

If you want to store multiple positions, you'll need a mutable array of some sort such as a List, so instead of aPosition = i you'll have list.add(i)

like image 140
Luke Avatar answered Sep 18 '25 09:09

Luke