String str= "IPP,C,D";
String str2 = "1~15,16~18|0|0,1,2,3,4,5,6"; Hashtable<String,List<Integer>> appname = new Hashtable<String,List<Integer>>();
补充:1~15 是 1,2,3,4,5,,,,15;
16~18 同上;
后两个也可能出现~ 0~3
结果输出是
IPP 0
IPP 1
IPP 2
到
IPP 15
IPP 16
IPP 18
C 0
D 0
D 1
要装到 Hashtable 里 String IPP List<Integer> 0 到15的数字
String str2 = "1~15,16~18|0|0,1,2,3,4,5,6"; Hashtable<String,List<Integer>> appname = new Hashtable<String,List<Integer>>();
补充:1~15 是 1,2,3,4,5,,,,15;
16~18 同上;
后两个也可能出现~ 0~3
结果输出是
IPP 0
IPP 1
IPP 2
到
IPP 15
IPP 16
IPP 18
C 0
D 0
D 1
要装到 Hashtable 里 String IPP List<Integer> 0 到15的数字
String keyString="A,B,C,D,E";
String valueString="1,2,3,4,5|6,7,8,9|10,11|12,13,14,15|16|0,17,18";
String[] keys=keyString.split(",");
String[] values = valueString.split("\\|");
Hashtable<String, List<Integer>> result = new Hashtable<String, List<Integer>>();
List<Integer> vl=new ArrayList<Integer>();
for(int i=0; i<keys.length;i++){
if(values[i]!=null){
for(String v:values[i].split(",")){
vl.add(Integer.parseInt(v));
System.out.println(keys[i]+" "+v);
}
result.put(keys[i], vl);
}
vl.clear();
}
LZ想要这个吗?
import java.util.Hashtable;
import java.util.List;public class ASADAD {public static void main(String[] args) {
Hashtable<String,List<Integer>> ht = new Hashtable<String,List<Integer>>();
String str1 = "IPPLAT,CMNET,DCN";
String str2 = "1~15,16~18|0|0,1,2,3,4,5,6";
String[] s1=str1.split(",");
String[] s2=str2.split("\\|");
for (int k = 0; k < s1.length; k++) {
List<Integer> result=new ArrayList<Integer>();
for (int i = 0; i < s2.length; i++) {
if(i==k){
String[] s3=s2[i].split(",");
for (int j = 0; j < s3.length; j++) {
if(s3[j].indexOf("~")>0){
int a=Integer.parseInt(s3[j].substring(0, s3[j].indexOf("~")));
int b=Integer.parseInt(s3[j].substring(s3[j].indexOf("~")+1,s3[j].length()));
for (int l = a; l <= b; l++) {
result.add(l);
}
}
else{
result.add(Integer.parseInt(s3[j]));
}
}
}
}
//System.out.println(s1[k]+":"+result);
ht.put(s1[k], result);
}
System.out.println(ht);
}}
class Test {
public static void main(String[] args) {
String str = "IPP,C,D";
String str2 = "1~15,16~18|0|0,1,2,3,4,5,6";
Hashtable <String, List<Integer>> appname = new Hashtable <String, List<Integer>>();
String[] name1 = str.split(",");
String[] name2 = str2.split("[|]");
for (int i=0; i<Math.min(name1.length, name2.length); i++) {
List<Integer> list = new ArrayList<Integer>();
appname.put(name1[i], list);
String t = name2[i];
if (t.contains(",")) {
String[] tt = t.split(",");
for (String s : tt) {
if (s.contains("~")) {
String[] ff = s.split("~");
if (ff.length==2) {
if (ff[0].matches("\\d+") && ff[1].matches("\\d+")) {
for (int j=Integer.valueOf(ff[0]); j<=Integer.valueOf(ff[1]).intValue(); j++) {
list.add(j);
}
} else if (ff[0].isEmpty()) {
for (int j=0; j<=Integer.valueOf(ff[1]).intValue(); j++) {
list.add(j);
}
}
} else {
if (ff[0].matches("\\d+")) {
list.add(Integer.valueOf(ff[0]));
}
}
} else {
if (s.matches("\\d+")) {
list.add(Integer.valueOf(s));
}
}
}
} else {
if (t.matches("\\d+")) {
list.add(Integer.valueOf(t));
}
}
} for (Map.Entry<String, List<Integer>> e : appname.entrySet()) {
System.out.printf("String:%s, List:%s\n", e.getKey(), e.getValue());
}
}
}