Java Common class set interface and implementation method summary

Source: Internet
Author: User
Tags addall

Recently learned Map-reduce principle and map-reduce programming, Ushun with learning under Java programming, for Java commonly used data structure and class set, I summarize to mind diagram, easy to clarify the relationship between each other


Package Leiji;

Import java.util.ArrayList;

Import java.util.List;

Import java.util.Collection;

public class Arrylist {

public static void Main (String args[]) {

List arrlt=new ArrayList ();

Collection acoll=new ArrayList ();

Arrlt.add ("Hello");

Arrlt.add (0, "World");

System.out.println (ARRLT);

add element

Acoll.add ("Jerry");

Acoll.add ("Weibo");

Add Object

Arrlt.addall (Acoll);

Arrlt.addall (0,acoll);

System.out.println (ARRLT);

remove element

Arrlt.remove (1);

Arrlt.remove ("Weibo");

System.out.println (ARRLT);

     

Get element

for (int i=0;i<=arrlt.size () -1;i++) {

System.out.println (Arrlt.get (i));

}

// String a[] =new string[]{"1", "2"};

To change a collection to an array of objects

String Str[]=arrlt.toarray (New string[]{});  //

for (int i=0;i<=str.length-1;i++) {

System.out.println (Str[i]);

}

Object Obj[]=arrlt.toarray ();

for (int i=0;i<=obj.length-1;i++) {

System.out.println (String) obj[i]);

}

Determines whether the empty

System.out.println (Arrlt.isempty ());

Determine if an element is included

System.out.println (Arrlt.contains ("Hello")? " Hello is contains ":" Hello is not contains ");

Intercept sub-collections

List l=arrlt.sublist (1, 4);

for (int i=0;i

System.out.println (L.get (i));

}

System.out.println (L.indexof ("Hello"));

}

}

Java Common class set interface and implementation method summary

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.