对于Java是否具有“IN”运算符或类似SQL的函数?感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍java有include吗,并为您提供关于C++重载运算符练习--对people类重载“==
对于Java是否具有“ IN”运算符或类似SQL的函数?感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍java有include吗,并为您提供关于C++重载运算符练习--对people类重载“= =”运算符和“=”运算符、Go 是否具有类似于 Python 的“if x in”结构?、Go是否具有lambda表达式或类似内容?、Go是否具有类似于Python的“ if x in”构造?的有用信息。
本文目录一览:- Java是否具有“ IN”运算符或类似SQL的函数?(java有include吗)
- C++重载运算符练习--对people类重载“= =”运算符和“=”运算符
- Go 是否具有类似于 Python 的“if x in”结构?
- Go是否具有lambda表达式或类似内容?
- Go是否具有类似于Python的“ if x in”构造?
Java是否具有“ IN”运算符或类似SQL的函数?(java有include吗)
我想知道是否有一种方法可以在Java中执行以下操作:
if(word in stringArray) { ...}
我知道我可以为此做一个函数,但是我只想知道Java是否已经为此做了一些事情。
谢谢!
答案1
小编典典有很多集合可以让您做类似的事情。例如:
与Strings
:
String s = "I can has cheezeburger?";boolean hasCheese = s.contains("cheeze");
或搭配Collections
:
List<String> listOfStrings = new ArrayList<String>();boolean hasString = listOfStrings.contains(something);
但是,对于简单的,没有类似的构造String[]
。
C++重载运算符练习--对people类重载“= =”运算符和“=”运算符
- 题目描述
对people类重载“= =”运算符和“=”运算符,“==”运算符判断两个people类对象的id属性是否相等;“=”运算符实现people类对象的赋值操作。 - 代码如下
#include<iostream>
#include<string>
using namespace std;
class Data{
public:
Data(){}
Data(int yy,int mm,int dd){
year=yy;
month=mm;
day=dd;
}
Data(Data &ap){
year=ap.year;
month=ap.month;
day=ap.day;
}
~Data(){
}
int get_year(){
return year;
}
int get_month(){
return month;
}
int get_day(){
return day;
}
void set_year(int y){
year=y;
}
void set_month(int m){
month=m;
}
void set_day(int d){
day=d;
}
private:
int year;
int month;
int day;
};
class People{
public:
People(int num,string se,Data birth,string iid):birthday(birth){
number=num;
sex=se;
id=iid;
}
People(People &tp){
number=tp.get_number();
sex=tp.get_sex();
id=tp.get_id();
birthday=tp.get_birthday();
}
People(){}
People get_People(){
int num,yy,mm,dd;
string ID,se;
cout<<"Please enter the number of the People:"<<endl;
cin>>num;
cout<<"Please enter the sex:(male or female)"<<endl;
cin>>se;
cout<<"Please enter the birthday:"
<<"(Warning the format is 1998 8 3.)"<<endl;
cin>>yy>>mm>>dd;
cout<<"Please enter the id:"<<endl;
cin>>ID;
Data birth(yy,mm,dd);
id=ID;
number=num;
sex=se;
birthday=birth;
return *this;
}
~People(){}
void set_number(int num){
number=num;
}
void set_sex(string se){
sex=se;
}
void set_birhtday(Data birth){
birthday=birth;
}
void set_id(string iidd){
id=iidd;
}
inline int get_number(){
return number;
}
inline string get_sex(){
return sex;
}
Data get_birthday()
{
return birthday;
}
inline string get_id(){
return id;
}
void details(){
cout<<"Number:"<<number<<endl;
cout<<"Sex:"<<sex<<endl;
cout<<"Birthday:"<<birthday.get_year()<<"/"<<birthday.get_month()<<"/"<<birthday.get_day()<<endl;
cout<<"ID:"<<id<<endl;
}
People& operator=(const People &p1){
if(this==&p1){
return *this;
}
number=p1.number;
sex=p1.sex;
birthday=p1.birthday;
id=p1.id;
}
private:
int number;
string sex;
Data birthday;
string id;
friend bool operator== (const People &p1,const People &p2){
if(p1.id==p2.id)
return true;
else
return false;
}
};
int main()
{
People asp,tcp,tmp;
asp.get_People();
asp.details();
tcp.get_People();
tcp.details();
if(asp==tcp)
cout<<"The id of two people is common!!!"<<endl;
else
cout<<"The id of two people is different!!!"<<endl;
tmp=asp;
tmp.details();
return 0;
}
- 测试截图
Go 是否具有类似于 Python 的“if x in”结构?
如果不遍历整个数组,如何x
使用 Go检查数组中是否存在?语言有结构吗?
像Python: if "x" in array: ...
答案1
小编典典在 Go 中没有内置的操作符可以做到这一点。您需要遍历数组。您可以编写自己的函数来执行此操作,如下所示:
func stringInSlice(a string, list []string) bool { for _, b := range list { if b == a { return true } } return false}
如果您希望能够在不遍历整个列表的情况下检查成员资格,则需要使用映射而不是数组或切片,如下所示:
visitedURL := map[string]bool { "http://www.google.com": true, "https://paypal.com": true,}if visitedURL[thisSite] { fmt.Println("Already been here.")}
Go是否具有lambda表达式或类似内容?
Go是否支持lambda表达式或类似内容?
我想从使用lambda表达式(Ruby)的另一种语言移植库。
Go是否具有类似于Python的“ if x in”构造?
如果不 遍历整个数组,如何x
使用Go 检查数组中是否存在?语言有结构吗?
像Python: if "x" in array: ...
今天关于Java是否具有“ IN”运算符或类似SQL的函数?和java有include吗的分享就到这里,希望大家有所收获,若想了解更多关于C++重载运算符练习--对people类重载“= =”运算符和“=”运算符、Go 是否具有类似于 Python 的“if x in”结构?、Go是否具有lambda表达式或类似内容?、Go是否具有类似于Python的“ if x in”构造?等相关知识,可以在本站进行查询。
本文标签: