Java class usage experience csdn)

Source: Internet
Author: User

1. Method for limiting the end of a string (for example, let the end not include ,-,,)
While (strtrue. endswith ("+") | strtrue. endswith ("-") | strtrue. endswith (",") // filter out the ++ number at the end
Strtrue = strtrue. substring (0, strtrue. Length ()-1 );

2. Be sure to use = to compare numbers and. Equals (string) to compare strings. Otherwise, the = is always no!

3. There is no length limit for the string type security standard, but the maximum length of the string in JDK is generally 4 GB.

5. For Java classes, attribute variables of classes cannot be used in static methods!

6. For the iterator Interface
The iterator () method of the collection interface returns an iterator. The iterator interface method can access each element in the collection one by one in an iterative manner, and safely remove appropriate elements from the collection.
(1) Boolean hasnext (): determines whether another element is accessible.
Object next (): returns the next element to be accessed. If the collection ends, a nosuchelementexception exception is thrown.
(2) void remove (): deletes the object returned from the last access. This method must be followed by an element. If the set has been modified after the last access, the method will throw illegalstateexception. The deletion operation in iterator also affects the underlying collection.
That is, in a hasnext (), do not call the. Next () method multiple times. Otherwise, the nosuchelementexception exception may occur.

7. when converting a string to the integer type, do not use integer. getinteger ("23"), which may be converted to a null value, so it is first converted to an integer. convert parseint to int, and then force type conversion: New INTEGER (23!

8. display the time of a yyyy-mm-dd hh: mm
Import java. util .*;
Public class test {
Public static void main (string SRT [])
{
Date d = new date ();
Gregoriancalendar z = new gregoriancalendar ();
Z. settime (d );
String datetime = z. get (calendar. year) + "-" + Z. get (calendar. month) + "-" + Z. get (calendar. day_of_month) + "" + Z. get (calendar. hour) + ":" + Z. get (calendar. minute );
System. Out. println (datetime );
System. Out. println (D. tostring ());
}
}
9. Positive and Negative methods for double and float books:
Math. sinnum (..);

The information from the class library is shown below.
Class math
Java. Lang. Object
Java. Lang. Math
There are positive and negative numbers to solve your problem as follows:
Static double SIGNUM (double D)
Returns the SIGNUM function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero,-1.0 if the argument is less than zero.
Static float SIGNUM (float F)
Returns the SIGNUM function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero,-1.0f if the argument is less than zero

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.