-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?

ADM
  • 20,406
  • 11
  • 52
  • 83
PRO FIRE
  • 7
  • 3

1 Answers1

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

Parth Patel
  • 859
  • 2
  • 11
  • 28