-5

I want to check which part of string is equal to text, from part 0 to count.

So I tried this:

int count = 1;
int city = 0;
String finall = "gggg,dddd";
String[] separated = finall.split(",");

for (int i = 0; i < count; ++i)
            if (selectedCities.equals(separated[i])){
                city = 1;
            }

How to increment each time the i in 1 until it reaches the value of count?

5

1 Answer 1

0

I guess you want to implement like this:

String selectedCities = "Miami"; // Selected(Predefine) city
int count = 0;
int city = 0;
String finall = "California,Miami,Delawar,New Jursey";
String[] separated = finall.split(",");
count = separated.length; // find total city in array

for (int i = 0; i < count; ++i){
    if (selectedCities.equals(separated[i])){
        city = 1;
    }
}
System.out.println("City Count = "+city); //Here count will be 1

Hope It will be helpful

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.