时间格式化与运算
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());
集合与数组的互换
ArrayListlist=new ArrayList ();list.add("a");list.add("b");list.add("c");String[] strs1=list.toArray(new String[]{});String[] strs2=list.toArray(new String[list.size()]);
Listlist = new ArrayList (Arrays.asList(str2));//list= Arrays.asList(str2); //错误写法 返回的是java.util.Arrays.ArrayList 没有add方法list.add("add");System.out.println(list);
com.alibaba.fastjson与数组、字符串互换
//字符串转JSONArrayString result="[\"12312\",\"123123122\"]";JSONArray jsonArray=JSONArray.parseArray(result);System.out.println(jsonArray.toJSONString());//JSONArray 转 数组String [] strings=jsonArray.toArray(new String[jsonArray.size()]);// 数组 转 JSONObjectJSONObject jsonObject=new JSONObject();String[] arr=new String[]{"123","456"};jsonObject.put("data",arr);System.out.println(jsonObject.toJSONString());// 数组 转 JSONArrayJSONArray dn=new JSONArray();dn.addAll(Arrays.asList(arr));System.out.println(dn.toJSONString());