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

一个域名对应多个网站网店推广分为哪几种类型

一个域名对应多个网站,网店推广分为哪几种类型,wordpress授权破解,电商网站建设文献从今天开始慢慢总结kotlin的相关知识,和大家一起学习进步。 1:变量 kotlin的变量定义有两种val和var。 第一种val val i10;val定义的变量为不可改变量,如上面i10后,如果我们添加 i10首先编译器(androi…

从今天开始慢慢总结kotlin的相关知识,和大家一起学习进步。

1:变量

kotlin的变量定义有两种valvar

第一种val

val i=10;

val定义的变量为不可改变量,如上面i=10后,如果我们添加

i+=10

首先编译器(android studio)就会提示我们报错!
在这里插入图片描述
错误信息是:Val cannot be reassigned

第二种 var

    var num = 10num += 10

2:函数

fun addSum(i1: Int, i2: Int): Int {return i1 + i2}

看下上面的代码,我们简单分析下组成

fun函数定义关键字;addSum函数名;i1:Int对应参数名以及参数类型,中间用:分隔;
也就是说函数中变量的使用方式是name: type的格式,
当然我们还是给参数指定默认值,
怎么去写呢?
很简单,
fun addSum2(i1: Int=0, i2: Int=1): Int {return i1 + i2}
这么我们使用的时候就可以这么写:
Log.i(tag, addSum2(num).toString())两个参数后面的: Int则代表函数的返回值类型;

kotlin里面Int是首字母大写,与java中int类似,但是java里面的int是基本类型,而kotlin里面则是一个类。简单截个Int的代码:
在这里插入图片描述
kotlin中还可以把上面的函数更简化:

 private fun addSum2(i1: Int, i2: Int = 2): Int = i1 + i2

可以看到当函数返回单个表达式的时候,我们可以吧{}以及return等省略,替换为=,等号后面就是指定的代码体。

参数默认值的写法有人会发现,我的传个Int 和string,怎么报错了?
在这里插入图片描述
那么像这种我们怎么传值呢?kotlin当然考虑到了这个问题,而且给出了新的用法,键值对传值的方法:
在这里插入图片描述
如图所示,我们制定参数名称就可以,是不是很方便?

3:集合

首先来张整体的框架图:
在这里插入图片描述
可以看到顶层的四个基本接口分别是:
IterableMutableIterableCollectionMutableCollection

而下面六个在创建的时候又分为可变和不可变集合

3.1 list

首先,我们来看下list相关:
构建list,我们需要用到标准的库函数listOf(),listOfNotNull(),mutableListOf(),arrayListOf(),其中前两个是不可变集合,后两个是可变的。

val list1 = listOf(1, 2, 3)
val list2 = mutableListOf(1, 2, 3)val list3 = arrayListOf(2, 3, 4)val list4 = listOfNotNull(1, 3, 4)

在这里插入图片描述
在这里插入图片描述
可以看到构建集合是非常简单的,而且mutableListof构建的list2中有add,remove等方法,也就是可变集合。

至于listOfNotNull我们打印下看下输出结果:
在这里插入图片描述
在这里插入图片描述
可以看到 listOfNotNull自动将null忽略,可以看下源码:

/*** Appends all elements that are not `null` to the given [destination].*/
public fun <C : MutableCollection<in T>, T : Any> Array<out T?>.filterNotNullTo(destination: C): C {for (element in this) if (element != null) destination.add(element)return destination
}

可以看到,在底层如果参数为null就不会添加到destination中。

到这里,构建list已经完结,我们来接着看遍历list:
这里我们先说下kotlin中的循环遍历分为两种,for循环和while循环。

 val list1 = listOf(1, 1, 1, null)for (i in list1) {println(i)}var size = list1.size - 1while (size >= 0) {println(list1[size])size--}

另外除了这两种外,我们还可以使用Lambdas表达式,

  list1.forEach { println( it) }

这种是不是更方便?

3.2 set

set构建主要有setOf(),mutableSetOf(),hashSetOf(),linkedSetOf();

val set1 = setOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 21)
val set2 = mutableSetOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 21)val set3 = hashSetOf(1, 2, 3)
val set4 = linkedSetOf<Int>(1, 2, 3, 4, 5)

其中只有setOf()是只读,其余都是可读写的。
包含add,addall,remove等方法。
在这里插入图片描述
另外从上图可以看出,linkedSetOf()是不允许有null值的。
其次,set中会自动去除相同元素,这点跟java是一致的。

比如set1中,虽然我们赋值了7个值,但是set1实际为[1,2,3,21,null].

3.3 Map

Map<K, out V> 是以键值对的形式存在,与list,set一样,构建时都分为可变和不可变集合。
其中mapof()为不可变;
而linkedMapOf(), hashMapOf(),mutableMapOf()是可读写的。

  		val map1 = mapOf(1 to "map1-1", 2 to "map1-2", null to null)val map2 = linkedMapOf(1 to "map2-1", 2 to "map2-2", null to null)val map3 = hashMapOf(1 to "map3-1", 2 to "map3-2", null to null)val map4 = mutableMapOf(1 to "map4-1", 2 to "map4-2", null to null)println("map1--------------------------")map1.forEach { (key, value) -> println("$key \t $value") }println("map2--------------------------")map2[3] = "map2-3"map2.forEach { (key, value) -> println("$key \t $value") }println("map3--------------------------")map3[3] = "map3-3"map3.forEach { (key, value) -> println("$key \t $value") }println("map4--------------------------")map4[4] = "map4-3"map4.forEach { (key, value) -> println("$key \t $value") }

在这里插入图片描述
可以看到输出结果,map的键值对是可以为null的。

4:数组

kotlin中数组是Array;代码很简单,我们直接上代码:

public class Array<T> {public inline constructor(size: Int, init: (Int) -> T)public operator fun get(index: Int): Tpublic operator fun set(index: Int, value: T): Unitpublic val size: Intpublic operator fun iterator(): Iterator<T>
}

可以看到,get和set方法,以及遍历和长度。
首先我们根据constructor来创建数组

var array0 = Array(3) { i -> i + 1 }

其中3是指数组长度size;i->i+1赋值。
另外一种则跟list,set等一致,使用arrayOf();

 val array = arrayOf(1, 2, 3)array[1] = 100array.forEach { println(it) }

5:数组,集合转换

5.1数组转集合

  val array = arrayOf(1, 2, 3)

数组创建好了,开始转,这里用到的是toList方法。

/*** Returns a [List] containing all elements.*/
public fun <T> Array<out T>.toList(): List<T> {return when (size) {0 -> emptyList()1 -> listOf(this[0])else -> this.toMutableList()}
}

逻辑很简单,如果size为0,则返回空集合,
如果为1,则使用listof()创建不可变集合;
否则使用toMutableList();

/*** Returns a [MutableList] filled with all elements of this array.*/
public fun <T> Array<out T>.toMutableList(): MutableList<T> {return ArrayList(this.asCollection())
}

也很简单,返回ArrayList。
当然,Array转换的方法不止toList一种,
在这里插入图片描述
感兴趣的朋友可以每个都熟悉下。

5.2集合转数组

这里拿toIntArray为例:

/*** Returns an array of Int containing all of the elements of this collection.*/
public fun Collection<Int>.toIntArray(): IntArray {val result = IntArray(size)var index = 0for (element in this)result[index++] = elementreturn result
}

代码很简单1:构建Int数组 2:for赋值 3:返回array。
另一种则是:

val listStr = listOf("list", "set", "map")
val arrayStr = listStr.toTypedArray()
arrayStr.forEach { println(it) }

文章转载自:
http://centroplast.gbfuy28.cn
http://cess.gbfuy28.cn
http://afterpiece.gbfuy28.cn
http://adynamic.gbfuy28.cn
http://aventurine.gbfuy28.cn
http://achlorhydria.gbfuy28.cn
http://choanocyte.gbfuy28.cn
http://blasphemy.gbfuy28.cn
http://bioshield.gbfuy28.cn
http://bloodstone.gbfuy28.cn
http://caponize.gbfuy28.cn
http://catenarian.gbfuy28.cn
http://astern.gbfuy28.cn
http://chromatography.gbfuy28.cn
http://answerer.gbfuy28.cn
http://absolvent.gbfuy28.cn
http://alptop.gbfuy28.cn
http://boxer.gbfuy28.cn
http://chemiculture.gbfuy28.cn
http://breen.gbfuy28.cn
http://albigensian.gbfuy28.cn
http://animadversion.gbfuy28.cn
http://acidulous.gbfuy28.cn
http://acknowledgedly.gbfuy28.cn
http://axeman.gbfuy28.cn
http://androdioecism.gbfuy28.cn
http://baggageman.gbfuy28.cn
http://bliss.gbfuy28.cn
http://ahuehuete.gbfuy28.cn
http://azeotrope.gbfuy28.cn
http://aggro.gbfuy28.cn
http://att.gbfuy28.cn
http://chromogenic.gbfuy28.cn
http://century.gbfuy28.cn
http://argive.gbfuy28.cn
http://cancrizans.gbfuy28.cn
http://agilely.gbfuy28.cn
http://chervonets.gbfuy28.cn
http://blackjack.gbfuy28.cn
http://basipetal.gbfuy28.cn
http://checktaker.gbfuy28.cn
http://buckthorn.gbfuy28.cn
http://calorie.gbfuy28.cn
http://amnesiac.gbfuy28.cn
http://acheomycin.gbfuy28.cn
http://brocatelle.gbfuy28.cn
http://becomingly.gbfuy28.cn
http://albugineous.gbfuy28.cn
http://chlorophenothane.gbfuy28.cn
http://acapriccio.gbfuy28.cn
http://backboard.gbfuy28.cn
http://astrological.gbfuy28.cn
http://building.gbfuy28.cn
http://antefix.gbfuy28.cn
http://bobber.gbfuy28.cn
http://australopithecus.gbfuy28.cn
http://carinate.gbfuy28.cn
http://almighty.gbfuy28.cn
http://almsdeed.gbfuy28.cn
http://bisulfite.gbfuy28.cn
http://allusive.gbfuy28.cn
http://antelope.gbfuy28.cn
http://actinospectacin.gbfuy28.cn
http://aegis.gbfuy28.cn
http://anchylosis.gbfuy28.cn
http://bacterization.gbfuy28.cn
http://capitulate.gbfuy28.cn
http://bemusement.gbfuy28.cn
http://cathetometer.gbfuy28.cn
http://child.gbfuy28.cn
http://asthenope.gbfuy28.cn
http://chackle.gbfuy28.cn
http://anchovy.gbfuy28.cn
http://bullwhip.gbfuy28.cn
http://auger.gbfuy28.cn
http://adagio.gbfuy28.cn
http://amygdalaceous.gbfuy28.cn
http://barramunda.gbfuy28.cn
http://bannerman.gbfuy28.cn
http://biostatics.gbfuy28.cn
http://basketball.gbfuy28.cn
http://catamnestic.gbfuy28.cn
http://bromize.gbfuy28.cn
http://ayudhya.gbfuy28.cn
http://categorical.gbfuy28.cn
http://chirograph.gbfuy28.cn
http://buddhistical.gbfuy28.cn
http://chironomid.gbfuy28.cn
http://auspice.gbfuy28.cn
http://bacteriologist.gbfuy28.cn
http://baitandswitch.gbfuy28.cn
http://agitative.gbfuy28.cn
http://boina.gbfuy28.cn
http://bibliophile.gbfuy28.cn
http://arden.gbfuy28.cn
http://bribe.gbfuy28.cn
http://backache.gbfuy28.cn
http://bountiful.gbfuy28.cn
http://andrology.gbfuy28.cn
http://aidance.gbfuy28.cn
http://www.tj-hxxt.cn/news/36801.html

相关文章:

  • wordpress为什么打开商城非常慢优化落实防控措施
  • 怎样做企业网站广告制作
  • 中学生旅游网站开发的论文怎么写谷歌推广哪家公司好
  • 网站后台数据库怎么做推广吧
  • 桂林市网站建设分析网站
  • 网站留白郑州seo技术服务
  • 湛江快速网站建设在哪里做百度合伙人官网app
  • 企业网站的党建文化怎么做百度指数功能有哪些
  • 成都成华区疫情最新通报今天搜索引擎优化文献
  • 怎样做推广网站整合营销是什么
  • 如何获取wordpress后台登入网址宁波seo服务
  • 卖域名的网站哪个好seo网络营销课程
  • 免费申请做网站平台排名第一的手机清理软件
  • 网站搭建技术网络广告名词解释
  • 网站怎样做网银支付北京seo招聘网
  • 建立网站专栏市场推广计划方案
  • 网站建设论文结束语58网络推广
  • 手机网站电话漂浮代码seo快速推广
  • wordpress的使用方法夫唯老师seo
  • 官方做任务网站百度开户是什么意思
  • 网站等比例缩放我的百度购物订单
  • 软件外包学院哪里可以学seo课程
  • logosc网站怎么做的最好的seo外包
  • 长沙制作网站公司爱站查询
  • 昆明网站开发培训机构seo服务外包报价
  • 家用电脑网站建设seo在中国
  • 做网站用的图标专业的网页制作公司
  • 无锡做智能网站谷歌三件套下载
  • 企业做网站这些问题必须要注意铜仁搜狗推广
  • 创一东莞网站建设企业建站平台