API概述
应用程序编程接口
API——Java语言中提供的类、接口
API文档——对类、接口功能的说明文档
基本数据类型包装类
基本类型
结构简单,有8种:
byte,short,int,long,double,float,char,boolean
Java为每种基本类型提供了一个类分别为:
Byte,Short,Integer,Long,Double,Float,Character,Boolean
作用
作为和基本数据类型对应的类类型存在。
包含每种基本数据类型的相关属性如最大值、最小值等,以及相关的操作方法。
常用方法
package com.ff.note.intege;
public class IntegerDemo {
public static void main(String[] args) {
//用于表示int值的字节数。
System.out.println(Integer.BYTES);
//int可表示的最大最小值
System.out.println(Integer.MIN_VALUE);
System.out.println(Integer.MAX_VALUE);
//用于表示int值的位数。
System.out.println(Integer.SIZE);
//类型
System.out.println(Integer.TYPE);
int num0=10;
int num=2;
//构造方法
Integer num1=new Integer(123);
Integer num2=new Integer("23");
System.out.println(num2);
//进制
System.out.println(Integer.toBinaryString(num0));//2制
System.out.println(Integer.toHexString(num0));//16进制
System.out.println(Integer.toOctalString(num0));//8进制
//比较 //比较两个整数
System.out.println(Integer.compare(num,num0));
//若num1>num2则返回1
//若num1=num2则返回0
//若num1<num2则返回-1
System.out.println(Integer.min(num,num0));
//返回两个数中小的一个
System.out.println(Integer.max(num,num0));
//返回两个数中大的一个
//比较两个Integer对象
System.out.println(num1.compareTo(num2));
//若num1>num2则返回1
//若num1=num2则返回0
//若num1<num2则返回-1
//比较两个对象的地址
System.out.println(num1==num2);
//相同为True反之False
//比较两个对象包含的值
System.out.println(num1.equals(num2));
//相同为True反之False
// 转型
int a=10;
Integer b=new Integer(12);
int c=b.intValue();//将Integer类型转化为int型
byte c1=b.byteValue();//将Integer类型转化为byte型
short c2=b.shortValue();//将Integer类型转化为short型
long c3=b.longValue();//将Integer类型转化为long型
float c4=b.floatValue();//将Integer类型转化为float型
double c5=b.doubleValue();//将Integer类型转化为double型
System.out.print(c+"\t");
System.out.print(c1+"\t");
System.out.print(c2+"\t");
System.out.print(c3+"\t");
System.out.print(c4+"\t");
System.out.print(c5+"\t");
System.out.println();
Integer d=Integer.valueOf(a);//将整数型的转花为Integer型
Integer e=Integer.valueOf("123");//将字符串类型的数转花为Integer型
System.out.print(d+"\t");
System.out.print(e+"\t");
System.out.println();
String f=b.toString();//将Integer型整数转化为字符类型
System.out.println(f);
String f1=Integer.toString(1423);//将int型的数转化为String型
System.out.println(f1);
//将字符串参数解析为带符号的十进制整数
System.out.println(Integer.parseInt("-12345"));
System.out.println(Integer.parseInt("\u002D65432"));
System.out.println(Integer.parseInt("\u002B65432"));
}
}
package com.ff.note.intege;
public class ZhuangChai {
public static void main(String[] args) {
int num=10;
Integer num1=new Integer(20);
int a=num1;//自动拆箱————调用 intValue
int a1=num1.intValue();//等价
Integer b=num;//自动装箱————调用 valueOf()
Integer b1=Integer.valueOf(num);//等价
// 比较
int aa=10;
int aa1=201;
Integer bb=new Integer(11);
Integer bb1=new Integer(211);
//使用装箱创建对象时,若值在(-128~~127)之间时若两个对象值相同,则其地址也相同
Integer cc=Integer.valueOf(aa);
Integer cc1=Integer.valueOf(aa);
System.out.println(cc==cc1);
System.out.println(cc.equals(cc1));
//使用装箱创建对象时,若值不在(-128~~127)之间时若两个对象值相同,其地址不相同
Integer dd=Integer.valueOf(aa1);
Integer dd1=Integer.valueOf(aa1);
System.out.println(dd==dd1);
System.out.println(dd.equals(dd1));
// 使用 new+构造方法 创建对象时不管值是否在(-128~~127)之中,其地址都不相同
}
}
Object
Java中所有类的父类
toString
将对象输出时就会调用 tostring()
当类中没有定义 toString()时,会默认调用父类(Object)中的toString()
native 修饰的是本地方法,java不实现,调用操作系统实现
Object中的toString()将对象地址转化为16进制数输出
toString()方法可以在类中重写
package com.ff.note.object;
public class Test {
//Object中的toString()将对象地址转化为16进制数输出
/*public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}*/
/*
public final native void notify(); native 修饰的是本地方法,java不实现,调用操作系统实现
*/
String name;
@Override
public String toString() {
return name;
}
}
package com.ff.note.object;
public class ToString extends Object{
public static void main(String[] args) {
//将对象输出时就会调用 tostring()
Test test=new Test();
test.name="小小";
System.out.println(test);
}
}
equals
Object 中 equals比较的是对象的地址,等同于 “==”
而其他类基本上都重写了equals()方法,比较内容是否相等
package com.ff.note.object;
import java.util.Objects;
public class Test2 extends Object{
// Object 中 equals比较的是对象的地址,等同于 “==”
/* public boolean equals(Object obj) {
return (this == obj);
}*/
String name;
int age;
public Test2(String name,int age) {
this.name=name;
this.age=age;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Test2 test2 = (Test2) o;
return age == test2.age &&
Objects.equals(name, test2.name);
}
}
package com.ff.note.object;
public class Equals {
public static void main(String[] args) {
Test2 s=new Test2("小小",17);
Test2 s1=new Test2("小小",17);
System.out.println(s==s1);
System.out.println(s.equals(s1));
}
}
String类/StringBuffer类/StringBuilder类
String类
定义
字符串是多个字符组成的字符序列,是常量(值不能改变)
字符串对象的创建
1——
String str = “abc”
第一次创建时会在字符串常量池中检测有没有,如果有则指向该对象,否则就在字符串常量池中创建一个对象
2——
使用 new+构造方法 创建
package com.ff.note.string;
public class Chuangjian {
public static void main(String[] args) {
// 在字符串常量池中查找,若没有则创建
String str="qiaoxu";
String str1="qiaoxu";
System.out.println(str==str1);//true
System.out.println(str.equals(str1));//true
// new+构造方法 创建新对象
String strr=new String("xiaoxiao");
String strr1=new String("xiaoxiao");
System.out.println(strr==strr1);//false
System.out.println(strr.equals(strr1));//true
}
}
特性
字符串值是常量,不能改变,一旦改变则是在内存中创建了一个新的对象
字符串底层是 char数组存储,单个字符串进行存储
方法
构造方法
package com.ff.note.string;
public class Gouzao {
public static void main(String[] args) {
//创建了一个字符串对象值为—— ""
String str=new String();
//创建了一个字符串对象值为 "xiaoxiao"
String str1=new String("xiaoxiao");
}
}
常用方法
package com.ff.note.string;
public class Fangfa {
public static void main(String[] args) {
String str0=new String();
String str=new String("ABCDECFG");
String str1=new String("abcdecfg");
String str2=new String("XiaoXiao");
// 判断功能
System.out.println(str.equals(str1));//判断值是否相同
System.out.println(str.equalsIgnoreCase(str1));//判断值是否相同————不区分大小写
System.out.println(str1.contains("abc"));//父串是否包含子串
System.out.println(str0.isEmpty());//该字符串是否为空
System.out.println(str.startsWith("A"));//该字符串是否以“A”开头
System.out.println(str.endsWith("G"));//该字符串是否以“G”结尾
System.out.println(str.compareTo(str1));//比较值的大小,用于排序
System.out.println("c".compareTo("a"));//2
// 获取功能
System.out.println(str.length());//获取长度 底层是通过获取插入char[].length
System.out.println(str1.charAt(2));//获取字符串对应索引位置的元素
System.out.println(str.indexOf("C"));//获取字符第一次出现的位置(索引)————从前向后
System.out.println(str.indexOf("C",3));//从第三个位置开始查找字符第一次出现的位置
System.out.println(str.lastIndexOf("C"));//获取字符第一次出现的位置(索引)————从后向前
System.out.println(str.lastIndexOf("C",3));//从第三个位置开始查找字符第一次出现的位置————从后向前
String a=str1.substring(2);//从第二个位置开始截取返回一个新的字符串,原字符串不变
String b=str1.substring(2,5);//从第二个位置开始,第五个位置结束(不包含第五个位置)截取,返回一个新的字符串,原字符串不变
System.out.println(a);
System.out.println(b);
System.out.println(str1);
}
}
替换方法
package com.ff.note.string;
public class Tihuan {
public static void main(String[] args) {
// 字符串替换————替换的是所有的符合旧字符串的字符
String str=new String("lovexiaoxiao20000804love");
String str1=str.replace("love","LOVE");
String str2=str.replace("x","X");
System.out.println(str1);
System.out.println(str2);
System.out.println(str);
String str3=str.replaceAll("\\d","6");//用正则表达式匹配字符串,全部替换
String str4=str.replaceFirst("\\d","521");//替换符合要求的第一个字符串
System.out.println(str3);
System.out.println(str4);
String a=" asd ghahd ad d ";
String b=a.trim();//去掉字符串前后两端的空格
String c=a.replaceAll(" ","");
System.out.println(c);
System.out.println(b);
System.out.println(a.length());
System.out.println(b.length());
System.out.println(c.length());
}
}
字符串转换
package com.ff.note.string;
import java.util.Arrays;
/*
static String valueOf(char[] chs)
String toLowerCase()
String toUpperCase()
String concat(String str)
Stirng[] split(String regex);
*/
public class Zhuanhuan {
public static void main(String[] args) {
String str="XiaoXiao";
char[] chars={'皮','卡','丘'};
String str1=String.valueOf(chars);//把char类型的数组转化为字符串
System.out.println(str1);
String str2=str.toUpperCase();//全部大写
String str3=str.toLowerCase();//全部小写
System.out.println(str2);
System.out.println(str3);
String str4=str.concat("love");//给字符串末尾加上指定字符串————字符拼接
System.out.println(str4);
String aa="123";
String bb="123";
String cc=aa+bb;//字符串拼接————效率最低,不建议使用
System.out.println(cc);
String a="xiao1:xiao2:xiao3:xiao4";
String[] b=a.split(":");//用字符分割
System.out.println(Arrays.toString(b));
String[] c=a.split("\\d");//用正则表达式分割字符串
System.out.println(Arrays.toString(c));
}
}
构造
package com.ff.note.string;
import java.io.UnsupportedEncodingException;
import java.time.format.SignStyle;
import java.util.Arrays;
public class Gouzao {
public static void main(String[] args) {
//创建了一个字符串对象值为—— ""
String str=new String();
//创建了一个字符串对象值为 "xiaoxiao"
String str1=new String("xiaoxiao");
String str2="皮卡丘";
byte[] bytes=str2.getBytes();//编码,转化为默认的字节数组
System.out.println(Arrays.toString(bytes));
try {
byte[] bytes1=str2.getBytes("utf-8");//编码,转化为 utf-8 的字节数组
byte[] bytes2=str2.getBytes("gbk");//编码,转化为 gbk 的字节数组
//utf-8 一个中文用3个字节表示
//gbk 一个中文用2个字节表示
String str4=new String(bytes1,"utf-8");//用指定编码解码
String str5=new String(bytes2,"gbk");//用指定编码解码
System.out.println(Arrays.toString(bytes1));
System.out.println(Arrays.toString(bytes2));
System.out.println(str4);
System.out.println(str5);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String str3=new String(bytes);//解码,字节转化为字符
System.out.println(str3);
String str4=new String(bytes,6,3);//转换指定位置和长度的字节
System.out.println(str4);
String a="皮卡丘";//把一个字符串转化为char数组
char[] chars=a.toCharArray();
System.out.println(Arrays.toString(chars));
String b=new String(chars);//构造函数把char数组转化为字符串
System.out.println(b);
String aa=String.valueOf(1234);//把各种类型转化为字符串
System.out.println(aa);
}
}
StringBuffer
package com.ff.note.string;
public class Stringbuffer {
public static void main(String[] args) {
StringBuffer str=new StringBuffer();
str.append("xiaoxiao20000804");
str.append("zaijian");//在字符串的末尾增加
System.out.println(str);
str.insert(4,"wo");//在指定索引处插入所给的字符串
System.out.println(str);
str.delete(0,4);//删除0~~4这一串字符,左闭右开
System.out.println(str);
str.deleteCharAt(0);//删除指定索引的字符
System.out.println(str);
str.replace(0,1,"jiuzhe");//替换指定位置的字符串
System.out.println(str);
StringBuffer str1=new StringBuffer("12345678loulou");
str1.reverse();//逆序
System.out.println(str1);
}
}
StringBuilder
package com.ff.note.string;
public class Stringbuilder {
public static void main(String[] args) {
StringBuilder str1=new StringBuilder("xiao");
str1.append("Xiao");//末未追加
System.out.println(str1);
str1.insert(8,"love");//在指定索引处插入字符串
System.out.println(str1);
str1.deleteCharAt(4);//删除指定索引处的字符
System.out.println(str1);
str1.delete(4,7);//删除指定位置的字符串,左闭右开
System.out.println(str1);
str1.replace(0,4,"loulou");//替换指定位置的字符串
System.out.println(str1);
str1.reverse();//逆序
System.out.println(str1);
}
}
String,StringBuffer,Stringbuilder的区别
String:内容不可变
StringBuffer:线程安全,内容可变
StringBuilder:内容可变
Arrays类
比较
Arrays.equals(a,b)——比较数组a和数组b包含的元素是否是相同的
package com.ff.note.arrays;
import java.util.Arrays;
public class Bijiao {
public static void main(String[] args) {
int[] a={2,0,0,0,8,4};
int[] a1={2,0,0,0,8,4};
int[] a2={2,0,0,0,8,26};
System.out.println(Arrays.equals(a,a1));
System.out.println(Arrays.equals(a,a2));
}
}
排序
基本类型
package com.ff.note.arrays.paixu;
import java.util.Arrays;
public class Jiben {
public static void main(String[] args) {
int[] a={2,4,1,5,3};
System.out.println(Arrays.toString(a));
Arrays.sort(a);
System.out.println(Arrays.toString(a));//排序是在原有数组的基础上进行的,会改变原有数组
int[] b={2,4,1,2,1};
Arrays.sort(b,0,3);//给数组a从索引0到索引3排序,不包过索引3
System.out.println(Arrays.toString(b));
}
}
引用类型
要实现compare接口
要重写compareTo方法——用于排序比较的方法,此方法在sort()中调用
在此方法中可自定义排序规则,用哪个属性比较的结果就会用那个属性排序
package com.ff.note.arrays.paixu;
public class Student implements Comparable<Student>{
private String name;
private int age;
private int time;//入学时间,年份
public Student(String name, int age, int time) {
this.name = name;
this.age = age;
this.time = time;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", age=" + age +
", time=" + time +
'}';
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
@Override
public int compareTo(Student o) {
return this.age-o.age;//小——>大
//return o.age-this.age; 大——>小
//return o.name.compareTo(this.name)
}
}
package com.ff.note.arrays.paixu;
import java.util.Arrays;
public class Yinyong {
public static void main(String[] args) {
Student student1=new Student("xiaoxiao",17,2018);
Student student2=new Student("loulou",12,2018);
Student student3=new Student("qiaoqiao",21,2018);
Student student4=new Student("luoluo",10,2010);
Student[] students={student1,student2,student3,student4};
System.out.println(Arrays.toString(students));
Arrays.sort(students);
System.out.println(Arrays.toString(students));
System.out.println(student1.getName());//获取
System.out.println(student2.getName());
System.out.println(student3.getName());
System.out.println(student4.getName());
//获取
for (Student st:students) {
System.out.println(st.getName()+":"+st.getAge()+"岁");
}
}
}
查找
Arrays.binarysearch(数组名,查找的元素)
若有则返回该元素所在位置的索引,否则返回负数
其底层使用二分折半查找,在数组有序时使用,数组无序时不能使用(结果有误)
可指定区间查找
package com.ff.note.arrays.paixu;
import java.util.Arrays;
public class Chazhao {
public static void main(String[] args) {
int[] a={2,5,1,0,4,6,3};
int index=Arrays.binarySearch(a,1);
Arrays.sort(a);
System.out.println(Arrays.toString(a));
int index2=Arrays.binarySearch(a,1);
int index3=Arrays.binarySearch(a,0,4,6);//指定范围,左闭右开
int index1=Arrays.binarySearch(a,8);
System.out.println(index);
System.out.println(index1);
System.out.println(index2);
System.out.println(index3);
}
}
数组复制
Arrays.copyOf(数组名,增加的长度)
会返回一个新的数组
当数组的长度不够用时,将原来的内容复制到新的数组中,可指定数组长度
package com.ff.note.arrays;
import java.util.Arrays;
public class Fuzhi {
public static void main(String[] args) {
int[] a={1,2,3,4,5};
int[] b=Arrays.copyOf(a,10);
System.out.println(Arrays.toString(a));
System.out.println(Arrays.toString(b));
System.out.println(a.length);
System.out.println(b.length);
}
}
泛型
参数化类型发,类型参数化
只能传引用类型,不传默认为Object类
package com.ff.note.fanxing;
import com.ff.ApiChangYong.day3.Ketang.FanXing;
//类型不确定,可以将类型作为参数传入,只能传入引用类型,如果不传默认是Object
public class Fanxing <T,N>{
private T t;
private N n;
public T ceshi(N n){
this.n=n;
return t;
}
public static void main(String[] args) {
FanXing<String> f=new FanXing<String>();//jdk1.8以后构造函数后<>中的可以不写
Fanxing<Integer,String> t=new Fanxing<>();
}
}
Math
方法的参数和返回值一般为double类型
abs——绝对值
sqrt ——平方根
pow(double a, double b) ——a的b次幂
max(double a, double b) ——返回a,b中大的一个
min(double a, double b) ——返回a,b中小的一个
random() ——返回 0.0 到 1.0 的随机数
long round(double a)—— double型的数据a转换为long型(四舍五入)
ceil——向上取整
floor——向下取整
round——四舍五入
package com.ff.note.math;
public class MathDemo {
public static void main(String[] args) {
double a=-12.12;
System.out.println(Math.abs(a));//绝对值
double a1=9;
System.out.println(Math.sqrt(a1));//a1的平方根
System.out.println(Math.pow(a1,2));//a1的2次方
System.out.println(Math.max(a,a1));//返回a,b中大的一个
System.out.println(Math.min(a,a1));//返回a,b中小的一个
System.out.println(Math.random());//返回 0.0 到 1.0 的随机数
double a2=12.4;
double a3=12.9;
double a4=12.5;
System.out.println(Math.ceil(a2));//向上取整
System.out.println(Math.floor(a3));//向下取整
System.out.println(Math.round(a2));//四舍五入
System.out.println(Math.round(a4));
}
}
Random
用于产生随机数
nextInt()——随机产生一个int类型的数
nextBoolean——随机产生一个boolean类型的数
nextInt(10)——随机产生一个 0到10 int类型的数 不包括10
nextInt(10)+10——扩大范围 10到20
nextByte(m)——给数组m随机赋值
package com.ff.note.random;
import java.util.Arrays;
import java.util.Random;
public class RandomDemo {
public static void main(String[] args) {
Random r=new Random();
System.out.println(r.nextInt());//随机产生一个int类型的数
System.out.println(r.nextBoolean());//随机产生一个boolean类型的数
System.out.println(r.nextInt(10));//随机产生一个 0到10 int类型的数// 不包括10
System.out.println(r.nextInt(10)+10);//扩大范围 10到20
byte[] b=new byte[10];
r.nextBytes(b);//给数组m随机赋值
System.out.println(Arrays.toString(b));
}
}
System
System 类包含一些有用的类字段和方法。它不能被实例化。
System.getenv();——获取信息,返回当前系统环境的不可修改的字符串映射视图
System.getenv(“path”)——获取环境变量的值
System.getpropeties();——确定当前的系统属性
System.getproperty("");——获取指定键指定的系统属性
System.exit(0);——关闭退出虚拟机
System.currentTimemillis();从1970年1月1日 0:0:0 到现在所经过的毫秒
System.arraycopy(复制的对象,从哪里开始复制,复制去的地方,复制到所去地方的开始索引,复制的长度);——数组复制
package com.ff.note.system;
import java.util.Arrays;
public class SystemDemo {
public static void main(String[] args) {
// System.getenv() 获取信息,返回当前系统环境不可修改的字符串映射视图
System.out.println(System.getenv());
// System.getenv("path") 获取环境变量得值
System.out.println(System.getenv("path"));
// System.getProperties() 确定当前系统属性
System.out.println(System.getProperties());
// System.getProperty("java") 获取指定键对应的系统属性
System.out.println(System.getProperty("java"));
// System.exit(0) 关闭java虚拟机
//System.exit(0);
// System.currentTimeMillis() 从1970年1月1日 0:0:0 至今的毫秒值得差
System.out.println(System.currentTimeMillis());
//System.arraycopy(复制的对象,开始位置,复制到哪,新对象开始的位置,复制长度)
int[] a={1,2,3,4,5};
int[] b=new int[a.length];
System.arraycopy(a, 0, b,0, a.length);
System.out.println(Arrays.toString(b));
}
}
Date
Date date=new Date() ———当前程序运行的那一刻时间
Date date=new Date(Long类型) ———long对应的时间
date.getYear()+1900 ————date的年份
date.getMonth() +1 ————date的月份
date.getDate() ————date的日期
date.getDay() +1 ————date的星期
date.setYear(t) ————设置date的年份 表示从1900年开始的第几年 即 年份=1900+t
package com.ff.note.date;
import java.util.Date;
public class Demo {
public static void main(String[] args) {
Date date1=new Date();// date 对象表示当前程序运行的那一刻的时间
Date date2=new Date(2001839138192L); // date 对象表示long类型的时间
System.out.println(date1);
System.out.println(date2);
// date.getYear()+1900 date对象时间的年份
System.out.println(date1.getYear()+1900);
// date.getMonth()+1 date对象时间的月份
System.out.println(date1.getMonth()+1);
// date.getDate() date对象时间的日期
System.out.println(date1.getDate());
// date.getDay()+1 date 对象时间的星期
System.out.println(date1.getDay()+1);
//date.setYear(t) 设置时间 设置的是从1900年开始后的第几年即此时年份=1900+t
date1.setYear(2);
System.out.println(date1);
}
}
Calendar 日历
该类为抽象类
创建一个表示当前时间的对象
Calendar rightnow =Calendar.getInstance();
Calendar rightnow1=new GregorianCalendar();
rightnow.get(Calendar.Year)————获取当前年份
righenow.getTime() ————获取当前时间 用标准格式表示
rightnow.getTimeInMillis() ————获取当前时间 用毫秒表示
rightnow.set(年份)
package com.ff.note.calendar;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class Demo {
public static void main(String[] args) {
Calendar rightnow=Calendar.getInstance();
System.out.println(rightnow);
Calendar rightnow1=new GregorianCalendar();
System.out.println(rightnow1);
// 获取当前年份
System.out.println(rightnow.get(Calendar.YEAR));
// 获取当前时间 用标准格式
System.out.println(rightnow.getTime());
// 获取当前时间 用毫秒表示
System.out.println(rightnow.getTimeInMillis());
// 设置日期为xxxx年xx月xx日
rightnow.set(2011, 2, 1);
System.out.println(rightnow.getTime());
}
}
SimpleDate Format 日期格式化
把日期对象转化为指定格式的字符串
把字符串抓化为日期对象
package com.ff.note.simpledateformat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Demo {
public static void main(String[] args) {
//date 转为指定格式字符串
SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss E");
String str= sdf.format(new Date());
System.out.println(str);
// 字符串转化为日期对象
String string="1999-08-26";
SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd");
try {
Date date=sdf1.parse(string);
System.out.println(date);
} catch (ParseException e) {
e.printStackTrace();
}
}
}