直接看代码吧。
package gdk.ware;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map.Entry;
import org.testng.annotations.Test;
//map的遍历
@Test
public class NewHashMap {
static HashMap<String, String> map=new HashMap<String,String>(){{put("a","a++");put("b","b++");}};
//遍历
public static void main()
{
System.out.println("开始遍历");
for(String key:map.keySet())
{
System.out.println("key:"+ key +", value="+map.get(key));
}
//遍历方法2
System.out.println("通过map.entrySet来遍历map");
for(Entry<String, String> entry:map.entrySet()){
System.out.println("key:"+ entry.getKey() +", value="+entry.getValue());
}
}
//倒序排列字符串
public void sort()
{
String a="abcde";
String b="";
char[] charArray=a.toCharArray();
for(int i=(charArray.length-1);i>=0;i--){
// System.out.println(b+=charArray[i]);
b+=charArray[i];
}
System.out.println(b);
}
//输出年月日时分秒
public void dateNow(){
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
Date date = new Date();
format.format(date);
System.out.println(date);
}
}