时间格式化与运算
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar=sdf.getCalendar(); calendar.setTime(sdf.parse(sdf.format(new Date()))); calendar.add(Calendar.DATE,1); System.out.println(calendar.getTime());
集合与数组的互换
ArrayList<String> list=new ArrayList<String>(); list.add("a"); list.add("b"); list.add("c"); String[] strs1=list.toArray(new String[]{}); String[] strs2=list.toArray(new String[list.size()]);
List<String> list = new ArrayList<String>(Arrays.asList(str2));
//list= Arrays.asList(str2); //错误写法 返回的是java.util.Arrays.ArrayList 没有add方法
list.add("add");
System.out.println(list);
com.alibaba.fastjson与数组、字符串互换
//字符串转JSONArray String result="["12312","123123122"]"; JSONArray jsonArray=JSONArray.parseArray(result); System.out.println(jsonArray.toJSONString()); //JSONArray 转 数组 String [] strings=jsonArray.toArray(new String[jsonArray.size()]); // 数组 转 JSONObject JSONObject jsonObject=new JSONObject(); String[] arr=new String[]{"123","456"}; jsonObject.put("data",arr); System.out.println(jsonObject.toJSONString()); // 数组 转 JSONArray JSONArray dn=new JSONArray(); dn.addAll(Arrays.asList(arr)); System.out.println(dn.toJSONString());