The Java.util package is called the Java Toolkit, which contains most of the tool classes
Stochastic random number class
New Random ()
Rd.nextint ()
Rd.nextint (100)
Scanner Scanner class
Scanner sc = new Scanner (system.in);
String str = Sc.next ();
String str1 = Sc.nextline ();
int t = Sc.nextint ();
float T = sc.nextfloat ();
Date Day Class
Date d = new Date (); Current time
Date d = new date (long); The specified time
D.gettime (); The number of milliseconds to get the current time
Date Formatting class
Simpledataformat to format a date time class
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss E");
String s = sdf.format (d);
Calendar class
Calendar C = calendar.getinstance ();
int year = C.get (calendar.year);
int month = C.get (calendar.month);
int day = C.get (calendar.day_of_month);
int hour = C.get (Calendar.hour_of_day);
int min = C.get (calendar.minute);
int sec = C.get (Calendar.second);
int w = c.get (Calendar.day_of_week);
The Ps:calendar class is an abstract class that needs to be implemented by the getinstance () method.
The conversion between the calendar and the date class is gettime () and SetTime (), respectively
Calendar object gets month will be one months less than the actual month, starting with subscript 0
The Calendar object gets Day_of_week is the number of days that gets to the current week, which is the weight of this Sunday to the current week.
TimerTask timed Task Class
Timer Timer
Define a class to inherit TimerTask, overriding the Run method
Create a Timer object
Create a Xxtask object
Start a task
Specify a task at a specified time
T.schedule (task, date);
Delay execution for a certain time
T.schedule (task, 500);
Delay execution for a certain period of time and repeat once every
T.schedule (Task, 5000, 1000);
Executes at a specified time, repeated at a certain time
T.schedule (Task, D, 1000);
Arrays Array Classes
BinarySearch (array, value) uses dichotomy to find the subscript position in the array where the value appears, and the precondition that the array must be ordered
Sort (array) sorting in arrays with quick-arrange method
ToString (array) converts an array into a string form
CopyOf (array, length) copy array, get a new array
Attached: Console Calendar Query procedure
1 PackageCom.work.calendar;2 3 ImportJava.util.Calendar;4 ImportJava.util.Scanner;5 6 7 Public classCalendardemo {8 intYear,month,day=0;9 //define an array of days to hold datesTen int[] days = {31,28,31,30,31,30,31,31,30,31,30,31}; One Calendar CAD; A /** - * Get the current date in a non-parametric construction method - */ the PublicCalendardemo () { -Cad=calendar.getinstance (); - This. Year =Cad.get (calendar.year); - This. Month=cad.get (Calendar.month) +1; + } - /** + * Pass a specific date to the Calendar object A * @param Year at * @paramMonth - * August 26, 2018 - */ - Public voidSetcalendardemo (intYearintmonth) { - This. Year =Year ; - This. Month =month; inCAD =calendar.getinstance (); - Cad.set (calendar.year, year); toCad.set (calendar.month,month-1); + } - /** the * will get to the calendar print * * $ * August 26, 2018Panax Notoginseng */ - Public voidlink () { the if(year/4==0&&year/100!=0| | year%400 ==0) { +days[1]=29; A}Else { theDays[1]=28; + } -SYSTEM.OUT.PRINTLN (year+ "year" +month+ "month"); $System.out.println ("t \ t two \ t three \ Four \ five \ t six"); $Cad.set (Calendar.day_of_month, 1); - intFirst =Cad.get (calendar.day_of_week); - for(inti = 0;i<first-1;i++) { theSystem.out.print ("\ t"); - }Wuyi for(inti=0;i<days[month-1];i++) { theSystem.out.print (i+1+ "\ T"); - if(first==7) { WuFirst=0; - System.out.println (); About } $first++; - } - } - Public Static voidMain (string[] args) { A intmonth,year; + BooleanFlag =true; theScanner sc =NewScanner (system.in); -System.out.println ("Please enter the year and month"); $Year =sc.nextint (); themonth =sc.nextint (); theCalendardemo C =NewCalendardemo (); the C.setcalendardemo (year, month); the C.link (); - while(flag) { in System.out.println (); theSYSTEM.OUT.PRINTLN ("Input a,d can view the calendar of the month, next months"); theSystem.out.println ("Enter R to exit the program"); About CharOperation = Sc.next (). CharAt (0); the if(operation== ' a ') { the if(month==1) { theYear = Year-1; +month = 12; -}Else { theMonth=month-1;Bayi } the}Else if(Operation = = ' d '){ the if(month==12) { -Year = Year+1; -month = 1; the}Else { theMonth=month+1; the } the}Else if(Operation = = ' R ') { -Flag =false; the } the C.setcalendardemo (year, month); the C.link ();94 System.out.println (); theSYSTEM.OUT.PRINTLN ("program has exited"); the } the sc.close ();98 } About}Calendardemo
Java Learning--java.util Common classes in packages