C++初阶--string

news2024/10/6 1:44:09
   

目录

string对象的创建:

遍历+修改

        const修饰的迭代器(只读):

        反向迭代器:

reserve与resize:

find,rfind,substr:

insert:

erase:

getchar、getline:

string对象比较:

stoi、to_string:

srting的模拟实现:

        简洁的string,不考虑增删查改(深浅拷贝):

        考虑增删查改:


    string是表示字符串的字符串类 ,该类的接口与常规容器的接口基本相同,又添加了一些专门用来操作string的接口,如字符串的比较等等。 string在底层实现是:basic_string模板类的别名,

typedef basic_string<char, char_traits, allocator> string; 不能操作多字节或者变长字符的序列。在使用string类时,要包含头文件以及std;
下面是C++官网对string类的介绍:

 

string对象的创建:

我们首先来看怎么创建string对象。

#include<iostream>
using namespace std;
#include <string>

int main()
{
	string s1;                      // 1 ...
	string s2("hello world");       // 2 ...
	string s3(s2);                  // 3  拷贝构造

	//cin >> s1;
	//cout << s1 << endl;
	cout << s2 << endl;
	cout << s3 << endl;

	string s4(s2, 2, 6);      //从第二个向后拷6个
	cout << s4 << endl;

	string s5(s2, 2);         //从第二个拷到最后
	cout << s5 << endl;

	string s6(s2, 2, 100);     //不全的话拷到结束
	cout << s6 << endl;

	string s7("hello world", 3); //拷前3个
	cout << s7 << endl;

	string s8(10, '!');         //拷10个 !
	cout << s8 << endl;

	return 0;
}

遍历+修改

接下来我们来看string对象的遍历,有三种方式实现:(迭代器是通用的遍历方式)

void test_string1()
{
	string s1("hello world");

	//遍历+修改
	//方式1:下标+[]
	for (size_t i = 0; i < s1.size(); i++)
	{
		s1[i] += 1;
	}

	for (size_t i = 0; i < s1.size(); i++)
	{
		cout << s1[i] << " ";
	}
	cout << endl;

	//方式2:迭代器
	string::iterator it = s1.begin();
	while (it != s1.end())
	{
		*it -= 1;
		++it;
	}

	it = s1.begin();
	while (it != s1.end())
	{
		cout << *it << " ";
		++it;
	}
	cout << endl;

	//方式3:范围for,自动往后迭代,自动判断结束
	for (auto& e : s1)
	{
		e -= 1;
	}
	for (auto e : s1)
	{
		cout << e << " ";
	}
	cout << endl;
}

const修饰的迭代器(只读):

void func(const string& s)
{
	//string::const_iterator it = s.begin();
	auto it = s.begin();
	while (it != s.end())
	{
		//*it -= 1;       //不可修改
		cout << *it << " ";
		++it;
	}
	cout << endl;

	string::const_reverse_iterator rit = s.rbegin();
	while (rit != s.rend())
	{
		//*rit = 'A';
		cout << *rit << " ";
		++rit;
	}
	cout << endl;
}

反向迭代器:

void test_string2()
{
	//反向迭代器
	string s1("hello world");
	//string::reverse_iterator rit = s1.rbegin();
	auto rit = s1.rbegin();
	while (rit != s1.rend())
	{
		cout << *rit << " ";
		++rit;
	}
	cout << endl;

	//list<int> lt(10, 5);
	//list<int>::iterator ltIt = lt.begin();
	while (ltIt != lt.end())
	{
		cout << *ltIt << " ";
		++ltIt;
	}
	cout << endl;
}

查看vs下的增容情况:

void TestPushBack()
{
	string s;
	//s.reserve(1000);     //申请至少能存储1000个字符的空间,不一定是1000个

	size_t sz = s.capacity();
	//cout << "capacity changed: " << sz << '\n';
	cout << "making s grow:\n";
	for (int i = 0; i < 1000; i++)
	{
		//s.push_back('c');
		s += 'c';
		if (sz != s.capacity())
		{
			sz = s.capacity();
			cout << "capacity changed: " << sz << '\n';
		}
	}
}

reserve与resize:

void test_string3()
{
	string s1;
	s1.reserve(1000);

	string s2;
	s2.resize(100, 'x');         

	string s3("hello world");
	s3.reserve(100);

	string s4("hello world");
	s4.resize(100, 'x');

	string s5("hello world");
	s5.resize(5);
}

find,rfind,substr:

void test_string4()
{
	string s("hello world");
	cout << s << endl;                 //运算符重载
	cout << s.c_str() << endl;         //字符的那个

	//string file("test.txt");
	//FILE* fout = fopen(file.c_str(), "w");

	要求取出文件后缀名
	//size_t pos = file.find('.');
	//if (pos != string::npos)
	//{
	//	//string suffix = file.substr(pos, file.size() - pos);
	//	string suffix = file.substr(pos);
	//	cout << suffix << endl;
	//}


	string file("test.txt.zip");
	FILE* fout = fopen(file.c_str(), "w");

	size_t pos = file.rfind('.');
	if (pos != string::npos)
	{
		//string suffix = file.substr(pos, file.size() - pos);
		string suffix = file.substr(pos);
		cout << suffix << endl;
	}

	string url("http://www.cplusplus.com/reference/string/string/");
	size_t pos1 = url.find(':');
	string protocol = url.substr(0, pos1 - 1);
	cout << protocol << endl;

	size_t pos2 = url.find('/', pos1 + 3);
	string domain =url.substr (pos1 + 3, pos2 - (pos1 + 3));
	cout << domain << endl;

	string uri = url.substr(pos2 + 1);
	cout << uri << endl;
}

insert:

void test_string5()
{
	string s("hello world");
	s += ' ';
	s += "!!!";
	cout << s << endl;

	//头插   效率O(N)
	s.insert(0, 1, 'x');
	s.insert(s.begin(), 'y');
	s.insert(0, "test");
	cout << s << endl;

	//中间插
	s.insert(4, "&&&");
	cout << s << endl;
}

erase:

void test_string6()
{
	string s("hello world");
	s.erase(0, 1);
	s.erase(s.size() - 1, 1);
	cout << s << endl;             //ello worl

	s.erase(3);
	cout << s << endl;             //ell
}

getchar、getline:

int main()
{
	string s1;

	//char ch = getchar();

	//while (ch != '\n')
	//{
	//	s1 += ch;
	//	ch = getchar();
	//}

	getline(cin, s1);

	cout << s1 << endl;

	return 0;
}

string对象比较:

void test_string7()
{
	string s1("hello world");
	string s2("string");
	cout << (s1 < s2) << endl;

	cout << ("hehe" < s2) << endl;
	cout << (s1 < "sport") << endl;
}

stoi、to_string:

void test_string8()
{
	int val = stoi("1234");          //i代表int,同理,double...
	cout << val << endl;

	string str = to_string(3.14);
	cout << str << endl;
}

srting的模拟实现:

简洁的string,不考虑增删查改(深浅拷贝):

//实现一个简洁的string,不考虑增删查改
namespace qwe
{
	class string
	{
	public:
		string(const char* str)
			:_str(new char[strlen(str) + 1])
		{
			strcpy(_str, str);
		}
		  
		传统写法
		s2(s1)
		//string(const string& s)
		//	:_str(new char[strlen(s._str)+1])
		//{
		//	strcpy(_str, s._str);
		//}

		s1=s3
		s3=s3
		//string& operator+(const string& s)
		//{
		//	if (this != &s)
		//	{
		//		char* tmp = new char[strlen(s._str) + 1];
		//		strcpy(tmp, s._str);
		//		delete[] _str;
		//		_str = tmp;
		//	}

		//	return *this;
		//}

		//现代写法
		//s2(s1)
		string(const string& s)
			:_str(nullptr)
		{
			string tmp(s._str);
			swap(_str, tmp._str);
		}

		//s1=s3
		/*string& operator=(const string& s)
		{
			if (this != &s)
			{
				string tmp(s);
				swap(_str, tmp._str);
			}

			return *this;
		}*/

		string& operator=(string s)
		{
			swap(_str, s._str);
			return *this;
		}

		~string()
		{
			if (_str)
			{
				delete[] _str;
				_str = nullptr;
			}
		}
	private:
		char* _str;
	};

	void test_string1()
	{
		string s1("hello world");
		string s2(s1);

		string s3("sort");
		s1 = s3;
		s3 = s3;
	}
}

考虑增删查改:

namespace qwe
{
	//增删查改
	class string
	{
	public:
		typedef char* iterator;
		typedef const char* const_iterator;

		const_iterator begin() const
		{
			return _str;
		}

		const_iterator end() const
		{
			return _str + _size;
		}
		
		iterator begin()
		{
			return _str;
		}

		iterator end()
		{
			return _str + _size;
		}

		/*string()
			:_str(new char[1])
			, _size(0)
			, _capacity(0)
		{
			_str[0] = '\0';
		}*/

		string(const char* str = "")
			:_size(strlen(str))
			, _capacity(_size)
		{
			_str = new char[_capacity + 1];
			strcpy(_str, str);
		}

		s2(s1)
		//string(const string& s)
		//	:_size(s._size)
		//	, _capacity(s._capacity)
		//{
		//	_str = new char[_capacity + 1];
		//	strcpy(_str, s._str);
		//}

		s1=s3
		s3=s3
		//string& operator=(const string& s)
		//{
		//	if (this != &s)
		//	{
		//		char* tmp = new char[s._capacity + 1];
		//		strcpy(tmp, s._str);
		//		delete[] _str;
		//		_str = tmp;
		//		_size = s._size;
		//		_capacity = s._capacity;
		//	}

		//	return *this;
		//}

		void swap(string& s)
		{
			std::swap(_str, s._str);
			std::swap(_size, s._size);
			std::swap(_capacity, s._capacity);
		}

		//s2(s1)
		string(const string& s)
			:_str(nullptr)
			, _size(0)
			, _capacity(0)
		{
			string tmp(s._str);
			swap(tmp);
		}

		//s1=s3
		string& operator=(string s)
		{
			swap(s);

			return *this;
		}

		~string()
		{
			delete[] _str;
			_str = nullptr;
			_size = _capacity = 0;
		}

		const char* c_str() const
		{
			return _str;
		}

		size_t size() const
		{
			return _size;
		}

		char& operator[](size_t pos)
		{
			assert(pos < _size);
			return _str[pos];
		}

		const char& operator[](size_t pos) const
		{
			assert(pos < _size);
			return _str[pos];
		}

		void reserve(size_t n)
		{
			if (n>_capacity)
			{
				char* tmp = new char[n + 1];
				strcpy(tmp, _str);
				delete[] _str;

				_str = tmp;
				_capacity = n;
			}
		}

		void resize(size_t n, char ch = '\0')
		{
			if (n <= _size)
			{
				_size = n;
				_str[_size] = '\0';
			}
			else
			{
				if (n > _capacity)
				{
					reserve(n);
				}

				memset(_str + _size, ch, n - _size);
				_size = n;
				_str[_size] = '\0';
			}
		}

		void push_back(char ch)
		{
			/*if (_size == _capacity)
			{
				reserve(_capacity == 0 ? 4 : _capacity * 2);
			}

			_str[_size] = ch;
			++_size;
			_str[_size] = '\0';*/
			insert(_size, ch);
		}

		void append(const char* str)
		{
			/*size_t len = strlen(str);
			if (_size + len > _capacity)
			{
				reserve(_size + len);
			}

			strcpy(_str + _size, str);
			_size += len;*/
			insert(_size, str);
		}

		string& operator+=(char ch)
		{
			push_back(ch);
			return *this;
		}

		string& operator+=(const char* str)
		{
			append(str);
			return *this;
		}

		size_t find(char ch)
		{
			for (size_t i = 0; i < _size; ++i)
			{
				if (ch == _str[i])
				{
					return i;
				}
			}

			return npos;
		}

		size_t fing(const char* s, size_t pos = 0)
		{
			const char* ptr = strstr(_str + pos, s);
			if (ptr == nullptr)
			{
				return npos;
			}
			else
			{
				return ptr - _str;
			}
		}

		string& insert(size_t pos, char ch)
		{
			assert(pos <= _size);

			if (_size == _capacity)
			{
				reserve(_capacity == 0 ? 4 : _capacity * 2);
			}

			size_t end = _size + 1;
			while (end > pos)
			{
				_str[end] = _str[end - 1];
				--end;
			}

			_str[pos] = ch;
			++_size;

			return *this;
		}

		string& insert(size_t pos, const char* s)
		{
			assert(pos <= _size);
			size_t len = strlen(s);
			if (_size + len > _capacity)
			{
				reserve(_size + len);
			}

			size_t end = _size + len;

			while (end >= pos+len)
			{
				_str[end] = _str[end - len];
				--end;
			}

			strncpy(_str + pos, s, len);
			_size += len;

			return *this;
		}

		string& erase(size_t pos = 0, size_t len = npos)
		{
			assert(pos < _size);

			if (len == npos || pos + len >= _size)
			{
				_str[pos] = '\0';
				_size = pos;
			}
			else
			{
				strcpy(_str + pos, _str + pos + len);
				_size -= len;
			}

			return *this;
		}

		void clear()
		{
			_str[0] = '\0';
			_size = 0;
		}
	private:
		char* _str;
		size_t _size;
		size_t _capacity;  //能存储有效字符的空间数,不包含\0

		static const size_t npos;
	};

	//"abcd"  "abcd" false
	//"abcd"  "abcde" true 
	//"abcde" "abcd" false
	bool operator<(const string& s1, const string& s2)
	{
		/*size_t i1 = 0, i2 = 0;
		while (i1 < s1.size() && i2 < s2.size())
		{
			if (s1[i1] < s2[i2])
			{
				return true;
			}
			else if (s1[i1] > s2[i2])
			{
				return false;
			}
			else
			{
				++i1;
				++i2;
			}
		}

		return i2 < s2.size() ? true : false;*/

		return strcmp(s1.c_str(), s2.c_str()) < 0;
	}

	bool operator==(const string& s1, const string& s2)
	{
		return strcmp(s1.c_str(), s2.c_str()) == 0;
	}

	bool operator<=(const string& s1, const string& s2)
	{
		return s1 < s2 || s1 == s2;
	}

	bool operator>(const string& s1, const string& s2)
	{
		return !(s1 <= s2);
	}

	bool operator>=(const string& s1, const string& s2)
	{
		return !(s1 < s2);
	}

	bool operator!=(const string& s1, const string& s2)
	{
		return !(s1 == s2);
	}

	//cout<<s1     operator<<(ostream& out, const string& s)
	ostream& operator<<(ostream& out, const string& s)
	{
		/*for (auto ch : s)
		{
			out << ch;
		}*/

		for (size_t i = 0; i < s.size(); ++i)
		{
			out << s[i];
		}

		//out << s.c_str();   // 不能这么写

		return out;
	}

	istream& operator>>(istream& in, string& s)
	{
		s.clear();

		char ch = in.get();
		while (ch != ' '&&ch != '\n')
		{
			s += ch;
			ch = in.get();
		}

		return in;
	}

	const size_t string::npos = -1;

	void f(const string& s)
	{
		cout << s[0] << endl;         //调用const修饰的[]
	}

	void test_string1()
	{
		string s1("hello world");
		string s2;
		cout << s1.c_str() << endl;
		cout << s2.c_str() << endl;

		s1[0] = 'x';
		for (size_t i = 0; i < s1.size(); ++i)
		{
			cout << s1[i] << " ";
		}
		cout << endl;
	}

	void test_string2()
	{
		string s1("hello world");
		string::iterator it = s1.begin();
		while (it != s1.end())
		{
			*it += 1;
			++it;
		}

		it = s1.begin();
		while (it != s1.end())
		{
			cout << *it << " ";
			++it;
		}
		cout << endl;

		//编译时会替换成迭代器
		for (auto e : s1)
		{
			cout << e << " ";
		}
		cout << endl;
	}

	void test_string3()
	{
		string s1("hello world");
		s1.push_back('#');
		s1.push_back('&');
		s1.append("hello world");
		cout << s1.c_str() << endl;

		string s2;
		s2 += 'x';
		s2 += "me 1";
		cout << s2.c_str() << endl;
	}

	void test_string4()
	{
		string s1("hello world");
		s1.insert(0, 'x');
		cout << s1.c_str() << endl;

		s1.insert(0, "abcd");
		cout << s1.c_str() << endl;
	}

	void test_string5()
	{
		string s1("hello world");
		s1.erase(5, 2);
		s1.erase(5, 20);
	}

	void test_string6()
	{
		string s1("abcd");
		string s2("abcd");
		cout << (s1 < s2) << endl;

		string s3("abcd");
		string s4("abcde");
		cout << (s3 < s4) << endl;

		string s5("abcde");
		string s6("abcd");
		cout << (s5 < s6) << endl;
	}

	void test_string7()
	{
		string s1("hello");
		cin >> s1;
		cout << s1;

		//string s1("hello");
		//s1 += '\0';
		//s1 += "world";
		//cout << s1 << endl;
		//cout << s1.c_str() << endl;
	}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/148555.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Java基础学习笔记(十一)—— 包装类与泛型

包装类与泛型1 包装类1.1 基本类型包装类1.2 Integer类1.3 自动装箱 / 拆箱2 泛型2.1 泛型概述2.2 泛型的用法2.3 类型通配符1 包装类 1.1 基本类型包装类 基本类型包装类的作用 将基本数据类型封装成对象 的好处在于可以在对象中定义更多的功能方法操作该数据 public stat…

✿✿✿JavaScript --- Ajax异步请求与JSONP 跨域请求

目 录 一、原生的Ajax请求 1.异步和同步 2.Ajax介绍 3.实现方式 (1)原生的JS实现方式&#xff08;了解&#xff09; (2)原生AJax发送Post请求&#xff0c;并携带请求参数 二、JQuery封装后的Ajax 1.JQeury实现方式 2. $.get()&#xff1a;发送get请求 3.$.post()&…

存储随笔2022年度最受欢迎文章榜单TOP15

回首2022感谢各位粉丝朋友的一路支持与陪伴存储随笔为您献上2022年度最受欢迎文章榜单TOP152023&#xff0c;一起向未来&#xff01;TOP1&#xff1a;固态硬盘SSD入门级白皮书主要从固态硬盘的原理/接口形态/寿命/使用场景/等不同角度&#xff0c;来对比不同的人群需要什么样的…

[linux]vim编辑器

&#x1f4df;作者主页&#xff1a;慢热的陕西人 &#x1f334;专栏链接&#xff1a;Linux &#x1f4e3;欢迎各位大佬&#x1f44d;点赞&#x1f525;关注&#x1f693;收藏&#xff0c;&#x1f349;留言 本博客主要讲解vim的使用和一些vim的常用操作&#xff0c;以及如何解决…

Flow 转 LiveData 后数据丢了,肿么回事?

翻译自&#xff1a; https://arkadiuszchmura.com/posts/be-careful-when-converting-flow-to-livedata/ 前言 最近我在负责一段代码库&#xff0c;需要在使用 Flow 的 Data 层和仍然依赖 LiveData 暴露 State 数据的 UI 层之间实现桥接。好在 androidx.lifecycle 框架已经提供…

C语言-指针进阶-函数指针数组应用-计算器(9.2)

目录 1. 函数指针 2. 函数指针数组 2.1函数指针数组的定义 2.2函数指针数组应用 3. 指向函数指针数组的指针 思维导图&#xff1a; 1. 函数指针 直接上代码&#xff1a; #include <stdio.h>void test() {printf("hehe\n"); }int main() {printf("%…

【Java】数组的复制、反转、查找、排序

数组的复制、反转、查找、排序 复制 其中最关键的一点是搞清楚为什么数组复制和基本数据类型复制不同&#xff0c;是什么导致了这样的不同&#xff1f; 先来看例子 package com.atguigu.java;public class ArrayTest3 {public static void main(String[] args) {//新建arr数…

【Java数据结构与算法】Day2-高级排序(希尔、归并、快速、计数)

✅作者简介&#xff1a;热爱Java后端开发的一名学习者&#xff0c;大家可以跟我一起讨论各种问题喔。 &#x1f34e;个人主页&#xff1a;Hhzzy99 &#x1f34a;个人信条&#xff1a;坚持就是胜利&#xff01; &#x1f49e;当前专栏&#xff1a;【Java数据结构与算法】 &#…

实验七:555定时器及其应用

答疑解惑用555定时器组成的单稳态电路中&#xff0c;若触发脉冲宽度大于单稳态持续时间&#xff0c;电路能否正常工作&#xff1f;如果不能&#xff0c;则电路应做如何修改&#xff1f;答:若触发脉冲宽度大于单稳态持续时间后&#xff0c;输出脉冲宽度将等于触发脉冲的低电平持…

【精】EditorConfig 小老鼠 跨编辑器 | IDE 保持一致的编码风格

【精】EditorConfig 小老鼠 跨编辑器 | IDE 保持一致的编码风格 &#x1f345;因发布平台差异导致阅读体验不同&#xff0c;将本文原编写地址贴出&#x1f339;&#xff1a;《【精】EditorConfig 小老鼠 跨编辑器 | IDE 保持一致的编码风格》 文章目录【精】EditorConfig 小老鼠…

实时数仓方案

2、实时数仓方案 2.1、为何需要实时数仓架构 随着数据量的增大&#xff0c;传统数据的方案在时效性上和数据维护上变得越来越困难。实时数仓架构应运而生。 具体方案落地上实时数仓有很多方案可以选择&#xff0c;不同的业务和应用场景到底应该选择哪种技术方案&#xff1f;…

React18新特性

React 团队在 2022 年 3 月 29 日正式发布了 React 的第 18 个版本。 在这篇文章里简单介绍 React 18 的新特性&#xff0c;React Concurrent Mode&#xff08;并发模式&#xff09;的实现&#xff0c;以及简要的升级指南。 New Features Automatic Batching 早在 React 18 之…

011-Ensp-实验-配置ACL

实验要求 1.通过ACL 使PC1无法访问PC3 实验结构 实验步骤 基础环境配置: PC间互通 1. PC1 2 3 配置IP网关 2. LSW2 创建三个vlan &#xff0c;g0/0/2 g0/0/3 g/0/04 类型配置为Access 分别加入三个vlan g0/0/1 配置为trunk 并允许所有vlan通过 3. LSW1 g0/0/1 配置trunk …

vector底层实现及深层次拷贝问题

目录 大框架 接口实现 深层次拷贝问题&#xff08;两次深拷贝&#xff09; 大框架 为了与库里实现的更接近一些&#xff0c;先来看一下STL中是如何实现vector的&#xff08;这里不是PJ版&#xff0c;PJ版稍微晦涩一点不容易理解&#xff0c;这里采用Linux下g的版本&#xf…

VectorNet: Encoding HD Maps and Agent Dynamics from Vectorized Representation

Paper name VectorNet: Encoding HD Maps and Agent Dynamics from Vectorized Representation Paper Reading Note URL: https://arxiv.org/pdf/2005.04259.pdf TL;DR waymo 出品的 CVPR2020 论文 &#xff0c;关注在自动驾驶场景&#xff08;复杂多智能体系统&#xff0…

【算法自由之路】快慢指针在链表中的妙用(下篇)

【算法自由之路】快慢指针在链表中的妙用&#xff08;下篇&#xff09; 继上篇之后&#xff0c;链表这块还有两个相对较难的问题我们继续举例。 问题 1 给定具有 random 指针的 next 方向无环单链表&#xff0c;复制该链表 单听这个问题可能有点懵&#xff0c;这个链表结构我…

PCB封装创建(CHIP类)

PCB封装要有以下内容 PCB焊盘管脚序号丝印阻焊1脚标识目录 CHIP类&#xff08;电阻 电容 电感 三极管&#xff09; 0805C 0805R 0805L SOT-23 1.CHIP类&#xff08;电阻 电容 电感 三极管&#xff09; 1.新建一个PCB元件库 打开PCB Library 以下以0805为例。 创建080…

“CAcModuleResourceOverride”: 未声明的标识符

本文迁移自本人网易博客&#xff0c;写于2011年10月8日首先是运行时提示&#xff1a;试图执行系统不支持的操作。添加CAcModuleResourceOverride resourceOverride; 后&#xff0c;编译出现如下错误&#xff1a;error C2065: “CAcModuleResourceOverride”: 未声明的标识符 添…

scikit-learn 普通最小二乘法

scikit-learn 普通最小二乘法什么是普通最小二乘法&#xff1f;参考文献什么是普通最小二乘法&#xff1f; 线性回归模型的数学表达式如下&#xff1a; y^(w,x)w0w1x1…wpx1\hat{y}(w, x)w_{0}w_{1} x_{1}\ldotsw_{p} x_{1}y^​(w,x)w0​w1​x1​…wp​x1​ 其中 w0,w1,...,w…

Java--集合

1、集合框架 集合框架被设计成要满足以下几个目标。 该框架必须是高性能的。基本集合&#xff08;动态数组&#xff0c;链表&#xff0c;树&#xff0c;哈希表&#xff09;的实现也必须是高效的。 该框架允许不同类型的集合&#xff0c;以类似的方式工作&#xff0c;具有高度的…