Basic operation based on List thread table

Source: Internet
Author: User

Package com.cn.list.base;

Import java.util.ArrayList;
Import java.util.List;

/**
* Basic operation based on List thread table
*
*/
public class Listoperation<t> {

Private list<t> List = null;

/**
* Initialize List linear table
*
* @param initialcapacity Thread table capacity
* @return List
*/
Public list<t> initlist (int initialcapacity) {
list = null;
List = new arraylist<t> (initialcapacity);
return list;
}

/**
* <p>
* Determine if the linear table is empty.
* <p>
*
* <li>true-Linear table is empty
* <li>false-linear table is not empty
*
* @return Boolean
*/
public Boolean isEmpty () {
if (null = = List | | list.size () <= 0) {
return true;
}
return false;
}

/**
* Empty Linear table
*/
public void Clearlist () {
List.clear ();
}

/**
* Returns the element of the specified index
*
* @param I index value
* @return elements in linear table
*/
@SuppressWarnings ({"Unchecked", "hiding"})
Public <T> T Getelem (int i) {
Return (T) list.get (i);
}

/**
* Find out if a t element exists in a linear table
*
* <li>true-Presence
* <li>false-not present
*
* @param t contrast element
* @return Boolean
*/
public boolean Locateelem (T-t) {
for (int i = 0;i < List.size (); i++) {
if (List.get (i). Equals (t)) {
return true;
}
}
return false;
}

/**
* Insert Element
*
* @param t element
*/
public void Insert (T t) {
List.add (t);
}

/**
* Return thread table length
*
* @return Thread table length
*/
public int Length () {
return List.size ();
}

/**
* Merge the specified linear table with the same element overlay
*
* @param lis to merge the linear table
*/
public void Union (listoperation<t> lis) {
for (int i = 0;i < Lis.length (); i++) {
T t = Lis.getelem (i);
if (!this.locateelem (t)) {
This.insert (t);
}
}
}

/**
* Print all elements in a linear table
*/
public void All () {
SYSTEM.OUT.PRINTLN (list);
}

}

Basic operation based on List thread table

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.