Technical support knowledge point summary for 11 weeks

Source: Internet
Author: User

Code summary:
[Java]
Package cn.com. cnstrong;
 
Import java. util. Date;
Import java. text. ParseException;
Import java. text. SimpleDateFormat;
 
 
 
 
Public class DataDemo
{
 
/**
* @ Param args
*/
Public static void main (String [] args)
{
// TODO Auto-generated method stub
Date date = new Date ();
System. out. println (date );

// Format the date at 10:30:07 on January 9
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss ");
String str = sdf. format (date );
System. out. println (str );

String s1 = "2010-10-10 ";
SimpleDateFormat sdf1 = new SimpleDateFormat ("yyyy-MM-dd"); // an exception must be caught.
Try // monitoring code
{
Date d1 = sdf1.parse (s1 );
System. out. println (d1 );

}
Catch (ParseException e)
{
E. printStackTrace ();
}
}
}

// Finally used for resource release
// Exceptions are thrown up layer by layer. 1. Non-runtime exceptions. 2. runtime exceptions ·
// Compile and explain the execution
// Must be captured
// Your code must be released
// Handle exceptions in a timely manner
// When handling exceptions in catch, make the parent class at the bottom when there is a parent class

 
[Java]
Package cn.com. cnstrong;
 
Public class StringBufferDemo {
 
/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
StringBuffer sb = new StringBuffer ();
Sb. append ("a1 ");
Sb. append ("a1 ");
Sb. append ("a1 ");
Sb. append ("a1 ");
System. out. println (sb. toString ());
System. out. println (sb. capacity (); // The default value is 16.
System. out. println (sb. length ());
 
}
 
}
[Java]
Package cn.com. cnstrong;
 
Public class StringDemo1 {
 
/*
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stus
String s = new String ("abc ");
String s1 = "abc ";
String s2 = new String ("abc ");
System. out. println (s = s1 );
System. out. println (s = s2 );
System. out. println (s2 = s1 );

 
}
 
}

 
[Java]
Package cn.com. cnstrong;
 
Public class StringDemo2 {
 
/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
String str1 = new String ("AB cd ");
String str2 = new String ("abcdwtryreuytrab ");
String str3 = "ABC ";//?
// What is the difference!
Str1 = "AB" + "cd"; // concatenates strings and three objects to produce a lot of garbage
// What is used?
//
System. out. println (str1.length ());
System. out. println (str1.startsWith ("AB "));
System. out. println (str1.indexOf ("AB"); // contains characters
System. out. println (str1.indexOf ("AB", 2 ));//?
System. out. println (str1.substring (3 ));//?
System. out. println (str1.trim () + "| ");
// Replace
// Trim // remove space
// Equals comparison content
// = Whether the same object
String str4 = "1, 2, 3, 4, 5, 6, 7, 8 ";
String array [] = str4.split (","); // capture String
For (String ss: array)
{
System. out. println (ss );

}
//



 
}
 
}

 
[Java]
Package cn.com. cnstrong;
 
Public class StringDemo3 {
 
/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
String str1 = "123 ";

// String --> int
Int num = Integer. parseInt (str1 );
{
System. out. println (num );
}
// Int --> String
String s1 = String. valueOf (num );
{
System. out. println (s1 );
}

// String --> float
Float f = Float. parseFloat (s1 );
{
System. out. println (f );
}
// Float --> String
String str2 = String. valueOf (f );
{
System. out. println (str2 );

}
// Auto-Boxed int -- Integer
Int num1 = 4;
Integer I = num1;
// Float f = Float. parseFloat (str1); automatic packing

// Automatically Unbox Integer -- int
Int num2 = I;
// Integer is the int packaging class
}
 
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.