package com.lky.test;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.Test;
public class mapTest {
public static String []keys=new String[]{"name","sex","email","phone"};
public static String []values=new String[]{"lky","male","1411074230@qq.com","016515151"};
public static Map<String,String> info=new HashMap<String,String>();
static{
for(int i=0;i<values.length;++i){
info.put(keys[i], values[i]);
}
}
@Test
public void testMap(){
for(Entry<String, String> entry:info.entrySet()){
System.out.println(entry.getKey()+"---"+entry.getValue());
}
System.out.println("---------------");
}
@Test
public void testMap1(){
for(String key:info.keySet()){
System.out.println(key+"--------"+info.get(key));
}
System.out.println("---------------");
}
@Test
public void testMap2(){
Iterator<Entry<String, String>> iterator=info.entrySet().iterator();
while(iterator.hasNext()){
Entry<String, String> s=iterator.next();
System.out.println(s.getKey()+"----------"+s.getValue());
}
}
}
package com.lky.test;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.junit.Test;
public class stringToElse {
//字符串和byte数组之间的转化
@Test
public void test() throws UnsupportedEncodingException{
String s="lky";
byte[] info=s.getBytes();
String s1=new String(info,"utf-8");
System.out.println(s1);
}
//字符串和Date之间的转化
@Test
public void test1() throws ParseException{
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date date= sdf.parse("2015-10-14");//将字符串转化成Date类型
System.out.println(date);
System.out.println(sdf.format(date));//将日期类型转化成字符串类型
}
//字符串和int之间的转化
@Test
public void test2(){
String s="1000";
int integer=Integer.parseInt(s);
System.out.println(integer);
System.out.println(Integer.valueOf(integer).toString());
}
}