search
HomeJavaJavagetting StartedWhat are the container classes in java

What are the container classes in java

Nov 27, 2019 pm 03:35 PM
javaContainer class

What are the container classes in java

Container classes in java: List(list), Set(set), Queue(queue) , Map(Map)

List (List): What we care about is the index. It is an interface, cannot instantiate objects, and can store repeated elements.

ArrayList (dynamic array):

List<String> l1=new ArrayList<String>();
			l1.add("许远志");
			l1.add("将最前");
			l1.remove(0);

Recommended related learning video tutorials: java learning

Please see the example:

//遍历
		for(String str:l1) {
			System.out.println(str);
		}
		for(int i=0;i<l1.size();i++) {
			System.out.println(l1.get(i));
		}
		//LinkedList(链表)方便数组的插入操作
		List<String> l2=new LinkedList<String>();
		l2.add("许远志");
		l2.add("许远志2");
		l2.add("许远志3");
		for(String str1:l2) {
			System.out.println(str1);
		}
		//Set(集):关心唯一性  对象无序存储  不能存储重复元素
		Set<String> s1=new HashSet<String>();
		s1.add("xuxu");
		s1.add("yuan");
		s1.add("zhi");
		s1.remove("zhi");
		for(String str:s1) {
			System.out.println(str);
		}
		//Map(映射)对象以键-值对应存储  key不允许有重复  value允许有重复
		Map<String,String> m=new HashMap<String,String>();
		m.put("apple","苹果");
	    m.put("book","书");
	    m.put("student","学生");
	    System.out.println(m.get("apple"));		    
	     
	    for(String key :m.keySet()) {
	    	System.out.println(key+":"+m.get(key));
	    }

java related article tutorial recommendation: java entry program

The above is the detailed content of What are the container classes in java. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools