【发布时间】:2015-08-28 18:40:51
【问题描述】:
我有一个String[] 和一个输入String:
String[] ArrayEx = new String[1];
String textInput = "a whole bunch of words"
我要做的是检查String 是否包含Array 中存在的单词,像这样。
例如:textInput = "for example" 和 ArrayEx[0] = "example"
我知道这种方法:
Arrays.asList(yourArray).contains(yourValue)
但它会检查完整的String 对吗?如何检查 String 是否包含数组中存在的特定 word。即使是来自ArrayList 我也没有问题。
如果是的话,我可以从String[] 得到那个词吗?即,在上述情况下,获取String“示例”。
编辑:
public void searchNearestPlace(String v2txt)
{
Log.e("TAG", "Started");
v2txt = v2txt.toLowerCase();
String[] places = {"accounting, airport, amusement_park, aquarium, art_gallery, atm, bakery, bank, bar, beauty_salon, bicycle_store, book_store, bowling_alley, bus_station, cafe, campground, car_dealer, car_rental, car_repair, car_wash, casino, cemetery, church, city_hall, clothing_store, convenience_store, courthouse, dentist, department_store, doctor, electrician, electronics_store, embassy, establishment, finance, fire_station, florist, food, funeral_home, furniture_store, gas_station, general_contractor, grocery_or_supermarket, gym, hair_care, hardware_store, health, hindu_temple, home_goods_store, hospital, insurance_agency, jewelry_store, laundry, lawyer, library, liquor_store, local_government_office, locksmith, lodging, meal_delivery, meal_takeaway, mosque, movie_rental, movie_theater, moving_company, museum, night_club, painter, park, parking, pet_store, pharmacy, physiotherapist, place_of_worship, plumber, police, post_office, real_estate_agency, restaurant, roofing_contractor, rv_park, school, shoe_store, shopping_mall, spa, stadium, storage, store, subway_station, synagogue, taxi_stand, train_station, travel_agency, university, veterinary_care, zoo"};
int index;
for(int i = 0; i<= places.length - 1; i++)
{
Log.e("TAG","for");
if(v2txt.contains(places[i]))
{
Log.e("TAG", "sensed?!");
index = i;
}
}
假设v2txt 是"awesome airport",即使所有其他日志都表明它正常工作,感知的日志也不会出现
编辑2:
我很尴尬,我犯了这样一个愚蠢的错误。我的数组被错误地声明了。每个, 之前应该有一个"。我真是个大白痴!
很抱歉会更改并通知您。
【问题讨论】:
-
各位为什么投反对票。有什么不对。也请告诉我。
-
是只有一个单词字符串的数组,还是数组条目也可以有完整的句子?
-
排列一到两个单词。和字符串句子
-
您想知道句子是否包含数组中的任何单词,还是仅包含数组中的(1 或 2 个单词)短语?
标签: java arrays string arraylist