The Java array is detailed

Source: Internet
Author: User

Package Com.keke.demo;

Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import java.util.ArrayList;
Import java.util.Collections;
Import Java.util.Comparator;
Import Java.util.Date;
Import Java.util.HashSet;
Import java.util.LinkedList;
Import java.util.List;
Import Java.util.Set;
Import Java.util.TreeSet;

Import com.sun.org.apache.xpath.internal.functions.Function;


Public final class Listdemo {

Final static public transient
int a = 100;
static int b = 100;

{
System.out.println ("Will this be done here?") +a + "= = =" +b);
}

Public Listdemo () {
System.out.println ("Here is where the construction method executes!");
}


public static void Main (string[] args) throws ParseException {

New Listdemo ();



Java.util.Collection Jdk-api
Collection interface-----List interface = = = Set interface
The list combines---ArrayList linkedlist Vector (ArrayList implements the same principle-thread-safe)//
Why do you have a collection?

Defining an array you quite open up an array of length 10--A dynamic array
The set condition element is called: Add (Object);
list<string> strings = new arraylist<string> ();//equivalent to string[] str = new STRING[10];
ArrayList and Vectory inside the JDK they are a dynamic array with a 1.5 * 10 + 1 Extension = 16--index--
Strings.add ("1");
Strings.add ("2");
Strings.add ("3");
Strings.add ("4");
Strings.add ("5");
Strings.add ("6");
Strings.add ("7");
Strings.add ("8");
Strings.add ("9");
Strings.add ("10");
Strings.add ("11");//Add to this line: the length of the array becomes: 16
The top of a generic =--data type range
linkedlist<string> LinkedList = new linkedlist<string> ();//Is he an array?
Linkedlist.add ("1");
Linkedlist.add ("2");
Linkedlist.add ("3");
Linkedlist.add ("4");
Linkedlist.add ("5");
Linkedlist.add ("6");
Linkedlist.add ("7");
Linkedlist.add ("8");
Linkedlist.add ("lucky");
Linkedlist.add ("10");
Gets the first value of an element
System.out.println ("The length of the linked collection is:" +linkedlist.get (0));
int length = Linkedlist.size ();
System.out.println ("The length of the linked collection is:" +length);
System.out.println ("The value of the last element of the linked collection is:" +linkedlist.get (length-1));
Linkedlist.remove (9);
Linkedlist.remove ("lucky");//This is based on the value of the element to remove

Length = Linkedlist.size ();
System.out.println ("The value of the last element of the linked collection is:" +linkedlist.get (length-1));
System.out.println ("The length of the linked collection is:" +length);


System.out.println ("==================set==============");
List: Ordered, with duplicate values allowed
Set: An unordered, and does not allow duplicate values
set<integer> set = new hashset<integer> ();
Set.add (1);
Set.add (2);
Set.add (2);
Set.add (1);
Set.add (3);
for (Integer Integer:set) {
System.out.println (integer);
//}
for (int i = 1; i <=; i++) {
Set.add (i);
//}
//
for (Integer Integer:set) {
System.out.println (integer);
//}

set<integer> Set2 = new linkedhashset<integer> ();//He is the equivalent of a heavy arrylist.
set<integer> Set2 = new treeset<integer> (new Mycomparator (false));//de-heavy and sort, from small to large sequencer
Set2.add (1);
Set2.add (2);
Set2.add (2);
Set2.add (10);
Set2.add (10);
Set2.add (30);
Set2.add (13);
Set2.add (23);
Set2.add (443);
Set2.add (355);
Set2.add (13);
Set2.add (23);
Set2.add (53);
Set2.add (73);
Set2.add (39);
Set2.add (13);
for (Integer Integer:set2) {
System.out.println (integer);
//}

set<date> dateset = new treeset<date> (new Datecomparator (true));
Dateset.add (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Parse ("2014-12-01 12:12:12"));
Dateset.add (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Parse ("2014-12-02 12:12:12"));
Dateset.add (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Parse ("2014-12-03 12:12:12"));
Dateset.add (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Parse ("2014-12-04 12:12:12"));
Dateset.add (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Parse ("2014-12-05 12:12:12"));
Dateset.add (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Parse ("2014-12-06 12:12:12"));
Dateset.add (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Parse ("2014-12-07 12:12:12"));
Dateset.add (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Parse ("2014-12-08 12:12:12"));
Dateset.add (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Parse ("2014-12-09 12:12:12"));

for (Date Date:dateset) {
System.out.println (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (date);
}


Gets the first value of the element
System.out.println ("The first element of a collection is:" +strings.get (0));
Gets the last value of an element
int length = Strings.size ();
System.out.println ("The length of the set is:" +length);
System.out.println ("The last element of the collection is:" +strings.get (length-1));
Strings.set (0, "1000");//Modify
System.out.println ("The first element of a collection is:" +strings.get (0));
Strings.remove (5);//delete the elements of the collection according to the subscript
Strings.set (0, NULL);
Strings.set (2, NULL);
Strings.add (NULL);

Use for to take value
System.out.println ("====== first type foreach loop");
for (String string:strings) {
System.out.println (string);
//}
//
System.out.println ("====== third iterator cycle");
iterator<string> Iterator = Strings.iterator ();
while (Iterator.hasnext ()) {
System.out.println (Iterator.next ());
//}

System.out.println ("====== second for Loop");



System.out.println ("============== date ===========");
Date date = new Date ();//java.util.date--1970 year
String format = "Yyyy-mm-dd HH:mm:ss";//This format is a fixed 24-hour system
String format = "Yyyy-mm-dd hh:mm:ss";//This format is a fixed 12-hour system

String format = "yyyy mm month DD day hh" in millimeters of SS seconds ";//This format is a fixed 12-hour system

String format = "mm month YYYY dd day hh" mm min ss second ";//This format is a fixed 12-hour system
String format = "mm month yyyy dd Day";//This format is a fixed 12-hour system
String format = "HH:mm:ss E";//This format is a fixed 12-hour system
String format = "yy-m-d h:m:s E w";//This format is a fixed 24-hour system
SYSTEM.OUT.PRINTLN (format). format (date);
//
String datestring = "2014/12/12 12:12:12";
Date date2 = new SimpleDateFormat ("Yyyy/mm/dd HH:mm:ss"). Parse (datestring);
System.out.println (DATE2);

Class: member inner class, Static inner class, anonymous inner class, local inner class (none yet seen in any one place, method defines Class)

This interface or abstract class, I have no subclasses of any kind
Rarely used.
}
}

The Java array is detailed

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.