System,integer,calendar,random and Containers

Source: Internet
Author: User
Tags set set

System

1) arraycopy

Int[] A = {1.2.3.4};  Int[5]; System.arraycopy (a,1,b,3,2);  copies the element in array a from subscript 1 to the position labeled 3 in array B, copying 2 elements in total     

2) Currenttimemillis

Long L = system.currenttimemillis ();  returns the difference between the current time and January 01, 1970 0:0 0 seconds (ms)  

3) GC: Request system for garbage collection

4) public static string GetProperty (String key): Gets the value of the property name key property, key can take java.version,os.name,user.name,user.dir and so on.

Integer class

1) and int conversion (java1.5 and above)

int m = +//int to integerint n = in;  integer to int    

2) Parseint: Converts a numeric string to an int value

String s = "123";  int n = Integer.parseint (s);  convert s to int by 16, for example S "FF", then get 255    

3) Convert Tostring:int into a string to make a binary

int parseint (String s,int radix)

Caledar Class (Java.util)

1) Create Calendar class to hold the current time

Calendar C = calendar.getinstance ();

2) Use the Calendar class to represent a specified time

Public final void Set (int year,int month,int date)//month minus 1 for the actual month
Calendar C = calendar.getinstance (); C.set (2009,3-1,9);

3) public void set (int field,int value)--only sets the value of a field, Feild can take value calendar.year,calendar.day_of_week, etc.

4) public int get (int feild)--Gets the corresponding information in the Calendar object.

5) public abstract void Add (int feild, int amount)

Increase the date by 100 days

C.add (calendar.date, 100);

6) Public Boolean after (Object when): Determines whether the current date is behind the When, returns True, otherwise false

void Main (string[] args) {    // TODO auto-generated method stub Calendar c = calendar.getinstance (); C.s ET (3-1,9); Calendar C1 = calendar.getinstance (); C1.set (5-1,9Long t1 =long t2 = long days= (t1-t2)/(24*60*60 *1000); System.out.println (days);}         

Random class (java.util)

1) public Random (long Seed)

New Random (10);

2) The probability of public boolean nextboolean ()//50% generates true or False

3) public int nextint ()///Generate -231~231-1 number

Number between public int nextint (int n)//build [0,n)

4) The decimal between public double nextdouble ()//Generate [0,1.0]

List Series

Commonly used are ArrayList and LinkedList.

New ArrayList ();        List.add ("1"), List.add ("2"),List.add ("3"), List.add ("1"), List.add ("1"// inserting 1 where the index is 12, The elements behind the next move // index value of 2 are set to a////delete an element with an index value of 1        

Set series: No Repetition allowed

New HashSet ();        Set.add ("1"), Set.add ("2"), Set.add ("3"), Set.add ("1"), Set.add ("1"), Set.remove ("1");  Delete 1 Inside the collection, there is no 1 in the collection Iterator Iterator = set.iterator ();  while (Iterator.hasnext ()) {System.out.println (String) Iterator.next ());}       

The above code output 3,2

Map series (Take HashMap as an example)

hashmap<string,double> map =New hashmap<string,double>(); Note that you cannot use double map.put ("Apple", 0.5); // delete key for Orange for Map.Remove ("Orange" ); // modify Apple's corresponding value map.put ("Apple", 1.2); Set set = Map.keyset () Iterator Iterator = Set.iterator ( ); while (Iterator.hasnext ()) {String key = (String) Iterator.next (); double value = (double) map.get (key); SYSTEM.OUT.PRINTLN (key + "\ T" +       

System,integer,calendar,random and Containers

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.