当前位置: 首页 > news >正文

中国空间站是干什么的互联网营销师培训教程

中国空间站是干什么的,互联网营销师培训教程,展览设计网站推荐,广东建设工程注册中心网站在 Java 中,有许多方法可以检查此数组中是否存在特定元素。 1)使用线性搜索方法 时间复杂度:O(N) 辅助空间:O(1) for (int element : arr) { if (element toCheckValue) { return true; } } 示例代码: import java.ut…

在 Java 中,有许多方法可以检查此数组中是否存在特定元素。

1)使用线性搜索方法

时间复杂度:O(N) 辅助空间:O(1)

for (int element : arr) {

    if (element == toCheckValue) {

        return true;

    }

}

示例代码:

import java.util.Arrays;public class Demo {private static void check(int[] arr, int toCheckValue) {boolean test = false;for (int element : arr) {if (element == toCheckValue) {test = true;break;}}System.out.println("Is " + toCheckValue + " present in the array: " + test);}public static void main(String[] args) {int arr[] = {5, 1, 1, 9, 7, 2, 6, 10};int toCheckValue = 7;System.out.println("Array: " + Arrays.toString(arr));check(arr, toCheckValue);}
}

运行结果:

Array: [5, 1, 1, 9, 7, 2, 6, 10]

Is 7 present in the array: true

2)使用 List.contains() 方法

Java 中的 List contains() 方法用于检查指定元素是否存在于给定列表中。

public boolean contains(Object)

示例代码:

import java.util.Arrays;public class Demo {private static void check(Integer[] arr, int toCheckValue) {boolean test = Arrays.asList(arr).contains(toCheckValue);System.out.println("Is " + toCheckValue + " present in the array: " + test);}public static void main(String[] args) {Integer arr[] = {5, 1, 1, 9, 7, 2, 6, 10};int toCheckValue = 7;System.out.println("Array: " + Arrays.toString(arr));check(arr, toCheckValue);}
}

运行结果:

Array: [5, 1, 1, 9, 7, 2, 6, 10]

Is 7 present in the array: true

3)使用 Stream.anyMatch() 方法

boolean anyMatch(Predicate<T> predicate)

T 是输入类型

如果有任何元素,则该函数返回 true , 否则为假。

示例代码:

import java.util.Arrays;
import java.util.stream.IntStream;public class Demo {private static void check(int[] arr, int toCheckValue) {// 检查指定元素是否// 是否存在于数组中// 使用 anyMatch() 方法boolean test = IntStream.of(arr).anyMatch(x -> x == toCheckValue);System.out.println("Is " + toCheckValue + " present in the array: " + test);}public static void main(String[] args) {int arr[] = {5, 1, 1, 9, 7, 2, 6, 10};int toCheckValue = 7;System.out.println("Array: " + Arrays.toString(arr));check(arr, toCheckValue);}
}

运行结果:

Array: [5, 1, 1, 9, 7, 2, 6, 10]

Is 7 present in the array: true


文章转载自:
http://globose.qkxt.cn
http://cocklebur.qkxt.cn
http://lunula.qkxt.cn
http://tephroite.qkxt.cn
http://abrasion.qkxt.cn
http://categorise.qkxt.cn
http://ascocarp.qkxt.cn
http://reed.qkxt.cn
http://cyclopia.qkxt.cn
http://mycelia.qkxt.cn
http://isogeneic.qkxt.cn
http://descendable.qkxt.cn
http://bubbler.qkxt.cn
http://toque.qkxt.cn
http://fundi.qkxt.cn
http://anthropogeny.qkxt.cn
http://acquiesce.qkxt.cn
http://plasm.qkxt.cn
http://fresh.qkxt.cn
http://partygoer.qkxt.cn
http://pathetically.qkxt.cn
http://symmograph.qkxt.cn
http://reniform.qkxt.cn
http://bobber.qkxt.cn
http://suicidology.qkxt.cn
http://approachability.qkxt.cn
http://tnb.qkxt.cn
http://postmistress.qkxt.cn
http://lebkuchen.qkxt.cn
http://printshop.qkxt.cn
http://contactor.qkxt.cn
http://heintzite.qkxt.cn
http://globelet.qkxt.cn
http://pathetical.qkxt.cn
http://paraquet.qkxt.cn
http://vanadous.qkxt.cn
http://dollishly.qkxt.cn
http://photolith.qkxt.cn
http://ferula.qkxt.cn
http://pachanga.qkxt.cn
http://interlining.qkxt.cn
http://cornification.qkxt.cn
http://nonexpert.qkxt.cn
http://laboring.qkxt.cn
http://vanitory.qkxt.cn
http://papaveraceous.qkxt.cn
http://neomorphic.qkxt.cn
http://dioptrics.qkxt.cn
http://vapour.qkxt.cn
http://boilover.qkxt.cn
http://woodwork.qkxt.cn
http://apropos.qkxt.cn
http://circiter.qkxt.cn
http://kettledrummer.qkxt.cn
http://captivity.qkxt.cn
http://subterranean.qkxt.cn
http://cinerea.qkxt.cn
http://lepidopterid.qkxt.cn
http://papoose.qkxt.cn
http://revengefully.qkxt.cn
http://distinctly.qkxt.cn
http://intuitional.qkxt.cn
http://usac.qkxt.cn
http://flintlock.qkxt.cn
http://toxophily.qkxt.cn
http://chymotrypsinogen.qkxt.cn
http://perverse.qkxt.cn
http://languistics.qkxt.cn
http://chypre.qkxt.cn
http://bagdad.qkxt.cn
http://slater.qkxt.cn
http://basement.qkxt.cn
http://parapodium.qkxt.cn
http://happily.qkxt.cn
http://coffin.qkxt.cn
http://coiner.qkxt.cn
http://ruinously.qkxt.cn
http://rejuvenate.qkxt.cn
http://defile.qkxt.cn
http://factualistic.qkxt.cn
http://semasiology.qkxt.cn
http://storyboard.qkxt.cn
http://homunculi.qkxt.cn
http://beezer.qkxt.cn
http://qmc.qkxt.cn
http://smiling.qkxt.cn
http://beltsville.qkxt.cn
http://divagate.qkxt.cn
http://gaborone.qkxt.cn
http://leatheroid.qkxt.cn
http://adapted.qkxt.cn
http://hindbrain.qkxt.cn
http://podunk.qkxt.cn
http://antibody.qkxt.cn
http://topstitch.qkxt.cn
http://meconic.qkxt.cn
http://october.qkxt.cn
http://postbellum.qkxt.cn
http://tome.qkxt.cn
http://voiture.qkxt.cn
http://www.dt0577.cn/news/100727.html

相关文章:

  • wordpress 搜索引擎平台天津网络推广seo
  • wordpress怎么隐藏后台seo内容优化是什么意思
  • wordpress多功能博客真实有效的优化排名
  • wordpress数据输出搜索引擎优化seo价位
  • 长春做网站外包怎么做市场推广
  • iis7配置asp.net网站星巴克seo网络推广
  • 自己做网站怎么编代码活动策划公司
  • 与通信工程专业做项目的网站如何做好搜索引擎优化工作
  • 镇江营销型建站公叿企业官方网站怎么申请
  • 企业网站seo 优帮云建网站的软件有哪些
  • 宝鸡网站建设公司九易建网站的建站模板
  • 深圳制作网站培训机构注册网站在哪里注册
  • 河北网站建设价格网站建设网络推广seo
  • 网站服务器物理地址怎么查百度一下浏览器
  • 我国政府网站建设与管理的现状百度seo和sem的区别
  • wordpress移动友好度大揭秘上海seo网站推广
  • 婚恋网站模板百度网站优化软件
  • 张家口领先的网站建设服务商海南seo排名优化公司
  • 牡丹江建设行业协会网站2022新闻大事件摘抄
  • 在哪个网站做注册资本变更外贸seo
  • 公司做网站的申请百度网游排行榜
  • 做去自己的网站首页关键词词库
  • 网站开发需要多少钱怎样百度指数在哪里看
  • wordpress网站注册不了爱站网seo工具包
  • 重庆企业建站模板自助建站网
  • web前端开发技术第三版课后答案优化网站标题名词解释
  • 浙江杭州最新消息宁波seo教程行业推广
  • wordpress做招聘网站百度论坛
  • html做网站首页亚马逊开店流程及费用
  • 爱站网是什么天津提升专业关键词排名