Java Fundamentals 9

Source: Internet
Author: User

1, how to get the current working directory?
String path=system.getproperty ("User.dir");


2. What is the difference between string x = "abc" and string x = new String ("abc")?
String x= "abc"; the x variable points to a string object in the data segment
string x = new String ("ABC") points to a string object in the heap, which must be copied into the object using a string in the data segment as a template;


3. What is the difference between string and StringBuffer?
String Immutable property, when we change it, does not change the contents of the string, but instead produces a new string object, less efficient,
The stringbuffer does not produce a new string, which is more efficient and is a buffer object;


4. How do I convert a string to a basic data type?
Data type variable = Data class. Parse Data type (the string);


5. How do I format the Date object for "2011-12-10" output? How do I convert a "2011-12-10" string to a date type?
SimpleDateFormat df=new SimpleDateFormat ("Yyyy-mm-dd");
String St=df.format (Date object);
System.out.println (ST);
Date D=df.parse (2011-12-10 ");

Java Fundamentals 9

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.