【发布时间】:2017-04-11 10:16:44
【问题描述】:
假设我们有两个字符串(ULR):
https://stackoverflow.com/questions/ask
https://web.whatsapp.com/
我需要写如下表达式:
如果在第三个斜线 (/) 之后什么都没有或第三个斜线不存在,则做
{
some operation
} else {
another action
}
请帮忙。
List<String> list = new ArrayList<String>();
while((str = in.readLine()) != null){
list.add(str);
}
String[] stringArr = list.toArray(new String[0]);
//copying and removing https from the list
List<String> list2 = new ArrayList<String>();
Collections.addAll(list2, stringArr);
Iterator<String> iter = list2.iterator();
while(iter.hasNext()){
if(iter.next().contains(https))
// here you should copy https lines to another file.
iter.remove();
}
String[] stringArr2 = list2.toArray(new String[0]);
for (int i = 0; i<stringArr2.length; i++) {
//condition for pure domain names.
//else the action below
System.out.println(getDomainName(stringArr2[i]) + "," + stringArr2[i] + "," + "U" +"," + number_of_doc + "," + today);
}
}
public static String getDomainName(String url) throws URISyntaxException {
URI uri = new URI(url);
String domain = uri.getHost();
return domain.startsWith("www.") ? domain.substring(4) : domain;
}
}
【问题讨论】:
标签: java string if-statement