[{2017,20},{2017,22}{2017,25}{2017,26}{2017,28},{2018,20}{2018,21}]
哪种语言这样表达一个数组的?
1 public static void main(String[] args) { 2 Object[] A = new Object[1]; 3 A[0]= "{2017,20},{2017,22}{2017,25}{2017,26}{2017,28},{2018,20}{2018,21}"; 4 String regex = (String)A[0]; 5 String[] date = regex.split("\\},\\{|\\}\\{|\\{|\\}"); 6 List<String> seventeen = new ArrayList<String>(); 7 List<String> eighteen = new ArrayList<String>(); 8 for(int i =0;i<date.length;i++) { 9 if(date[i].contains("2017")) { 10 String[] day = date[i].split(","); 11 seventeen.add(day[1]); 12 } 13 if(date[i].contains("2018")) { 14 String[] day = date[i].split(","); 15 eighteen.add(day[1]); 16 } 17 } 18 StringBuffer seventeenSB = new StringBuffer("2017:["); 19 seventeen.forEach(e -> { 20 seventeenSB.append("'"+e+"',"); 21 }); 22 StringBuffer eighteenSB = new StringBuffer("2018:["); 23 eighteen.forEach(e -> { 24 eighteenSB.append("'"+e+"',"); 25 }); 26 seventeenSB.delete(seventeenSB.length()-1, seventeenSB.length()); 27 eighteenSB.delete(eighteenSB.length()-1, eighteenSB.length()); 28 seventeenSB.append(']'); 29 eighteenSB.append(']'); 30 String str = new String("{"+seventeenSB+","+eighteenSB+"}"); 31 System.out.println(str); 32 }
有些简陋,算是给你个思路吧。
js数组?