Java knowledge,
1. Conversion encoding:
Str = new String (str. getBytes ("ISO-8859-1"), "UTF-8 ");
**************************************** **********************
2. Conversion between data types:
Int a = (int) B;
Int a = B. intValue ();
Int a = Ingtger. parseInt (B );
Integer a = new Integer (B );
Int I = Integer. valueOf (B). intValue ();
String type:
String a = B. toString ();
String a = B + "";
A. startsWith (B); // contains
A. endsWith (B); // contains
A. equals (B); // equal
A. Repeated signorecase (B); // case insensitive
A. contains (B); // contains
**************************************** ************************
3. size comparison of double Data Types
Double a = 0.01;
Double B = 0.001;
BigDecimal data1 = new BigDecimal ();
BigDecimal data2 = new BigDecimal (B );
Double result = data1.compareTo (data2 );
Data1> data2 result = 1;
Data1 <data2 result =-1;
Data1 = data2 result = 0;
**************************************** **********************************
4. the formula for converting an IP address to a Long value is as follows:
String [] oraginal = this. value. split ("\\.");
Long o = 0l; // Original Value
O + = Long. parseLong (oraginal [I]) <(24-I * 8 );
**************************************** **************************************** ****
5. Obtain the name of the current method.
String methodName = Thread. currentThread (). getStackTrace () [1]. getMethodName ();
**************************************** **************************************** **************
6. Singleton example for a single instance
Public class SimpleSingleton {
Private static SimpleSingleton singleInstance = new SimpleSingleton ();
// Marking default constructor private
// To avoid direct instantiation.
Private SimpleSingleton (){
}
// Get instance for class SimpleSingleton
Public static SimpleSingleton getInstance (){
Return singleInstance;
}
}
**************************************** **************************************** ***********************
7. encryption and decryption
Encrypt. encode ("admin ");
Encrypt. decode (str1), "UTF-8 ")
**************************************** **************************************** *******************************
8. mongodb usage
DBCursor result1 = templates. first1_template (). getCollection ("alarm "). find (bdb, keys ). sort (new BasicDBObject ("_ id",-1 )). limit (1, 1000 );
Gson gson = new Gson ();
While (result1.hasNext ()){
DBObject obj = result1.next ();
Map <String, Object> mapp = obj. toMap ();
Iterator <Map. Entry <String, Object> entries = mapp. entrySet (). iterator ();
While (entries. hasNext ()){
Map. Entry <String, Object> entry = entries. next ();
}
}