工作分割小记录
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了工作分割小记录相关的知识,希望对你有一定的参考价值。
测试类
@Test
public void ipfeng() {
String[] clients = {"android:1.5.0,1.6.0,1.6.1", "apple:1.5.0,1.6.0,1.6.1", "m:1.5.0,1.6.0,1.6.1", "pc:1.5.0,1.6.0,1.6.1"};
ArrayList<String> list = new ArrayList<>();
getClientVersions(clients);
}
公共类
public static ArrayList<ClientVersion> getClientVersions(String[] clients) {
//保存对象
ArrayList<ClientVersion> result = new ArrayList<>();
for(String clientVersion : clients) {
//分割对象
int sepIndex = clientVersion.indexOf(":");
System.out.println("sepIndex: "+sepIndex);
//分割后获前面字段
String client = clientVersion.substring(0, sepIndex);
System.out.println("client: "+client);
//通过split继续分割
String[] versions = clientVersion.substring(sepIndex + 1, clientVersion.length()).split(",");
for(String version : versions)
result.add(new ClientVersion(client, version));
}
Iterator<ClientVersion> iterator = result.iterator();
while (iterator.hasNext()) {
ClientVersion next = iterator.next();
System.out.println(next.getClient()+"...."+next.getClientVersion());
}
return result;
}
生存java实体
public class ClientVersion {
public String client;
public String clientVersion;
public ClientVersion(String client, String clientVersion) {
this.client = client;
this.clientVersion = clientVersion;
}
public String getClient() {
return client;
}
public String getClientVersion() {
return clientVersion;
}
}
以上是关于工作分割小记录的主要内容,如果未能解决你的问题,请参考以下文章