StringBuffer
1, StringBuffer and String are not directly related
2, StringBuffer to avoid the sring content changes in the phenomenon of garbage generation.
3. A StringBuffer object can call the ToString () method to convert to a string object.
The following is a small example of how the StringBuffer class is related:
Package stringbuffer; Public classStringbufferdemo { Public Static void Main(string[] args) {//TODO auto-generated method stub the structure of//* StringBufferStringBuffer BUF1 =NewStringBuffer ();//equivalent to an empty stringStringBuffer buf2 =NewStringBuffer ("123");//Construct StringBuffer object by stringSystem. out. println ("Below you can see a blank line plus the string" 123 ""+"\ n"+buf1+"\ n"+BUF2);/ * * Common methods * * */ //append () method to add charactersBuf1.append ("123"). Append (' C '). Append (23.2). Append (false); System. out. println ("Below you can see the string that is bridged by the Append () method:"+"\ n"+BUF1);//insert () method inserts a stringBuf1.insert (0,true). Insert (0,"First word Fu Chan insert"); System. out. println ("Below you can see the string after inserting a character before the specified position"+"\ n"+BUF1);The //delete () method deletes a substring of the specified range (a character starting at subscript 0)Buf1.delete (0,1); System. out. println ("Below you can see the string after deleting the specified position character"+"\ n"+BUF1);//reverse () method reverses string contentsBuf1.reverse (); System. out. println ("Below you can see the inverted string"+"\ n"+BUF1);//replace () method substitution characterBuf1.replace (0,1,"7788"); System. out. println ("You can see the replaced string below."+"\ n"+BUF1); }}
Runtime
Directly on the example, look at the effect!
Public class runtimedemo { /** * @param args * @throws ioexception * @throws interruptedexception */ Public Static void Main(string[] args)throwsIOException, Interruptedexception {//TODO auto-generated method stubRuntime r = Runtime.getruntime ();//Get Runtime instanceProcess Pro = R.exec ("Notepad");//Perform a native program "Notepad" //thread.sleep (5000);//sleep 5 secondsPro.destroy ();//Destroy the processSystem.out.println ("Native Memory:"+r.totalmemory ()); }}
System
Public class systemdemo { /** * Calculates the run time of a program * @param args */ Public Static void Main(string[] args) {//TODO auto-generated method stub LongStart = System.currenttimemillis (); System.out.println ("Current time:"+start); for(inti =0; I < -; i++) { for(intj =0; J < -; J + +) {j + +; } }LongEnd = System.currenttimemillis (); System.out.println ("Program Execution time:"+ (End-start)); }}
Date, Calendar
Public class datedemo { /** * @param args * * Public Static void Main(string[] args) {//TODO auto-generated method stub //Take a look at today's date, the format is a bit weirdSystem.out.println (NewDate ());the//calendar class, which is an abstract class that needs to be instantiated with its subclassesCalendar C =NewGregorianCalendar (); StringBuffer s =NewStringBuffer (); S.append (C.get (calendar.year) +"Year"+ (C.get (calendar.month) +1)+"Month"+ C.get (calendar.day_of_month) +"Day"+" "+c.get (Calendar.hour) +":"+c.get (Calendar.minute)); System.out.println (s); }}
The date of the above System.out.println (new date ()) output is not a habit, and the following will make you more vulnerable:
DateFormat
import Java.text.dateformat;import java.util.Date; public class Formatdemo {public static void main (string[] args) {//TODO auto-generated method Stub Date d = new date (); DateFormat f = dateformat.getdateinstance (); //get the default date formatting instance DateFormat ff = dateformat.getdatetimeinstance (); //get the default datetime formatted instance System. out . println (F.format (d)); //formatted after output System. out . println (Ff.format (d)); //formatted after output }}
The output is not accustomed to, but its format can not change it? The answer is yes, keep looking:
Import Java.text.dateformat;import java.util.Date; Public classFormatdemo { Public Static void Main(string[] args) {//TODO auto-generated method stubDate d =NewDate ();//instancing Date //The following method gives the parameters of theDateFormat f = dateformat.getdateinstance (Dateformat.full);//Get the default date format instanceDateFormat ff = dateformat.getdatetimeinstance (dateformat.full,dateformat.full);//Get the default datetime format instanceSystem. out. println (F.format (d));//Formatted outputSystem. out. println (Ff.format (d));//Formatted output}}
In fact, we can also have more formats, such as: 2015/5/26, next time to continue (-_-)
Common library of Basic Java Knowledge (1)