首页 > 其他分享 >Zgo - maps

Zgo - maps

时间:2024-06-11 11:44:15浏览次数:23  
标签:map fmt two three four maps Zgo

 

package main

import (
    "fmt"
    "maps"
)

func delete(k string, v int) bool {
    return v%2 != 0
}

func equal(v1 int, v2 float64) bool {
    return float64(v1) == v2
}

func main() {
    m := map[string]int{
        "one": 1, "two": 2,
        "three": 3, "four": 4,
    }

    fmt.Printf("%#v\n", m)
    maps.DeleteFunc(m, delete)
    fmt.Printf("%#v\n", m)

    n := maps.Clone(m)
    if maps.Equal(m, n) {
        fmt.Println(("Equal!"))
    } else {
        fmt.Println("Not equal!")
    }

    n["three"] = 3
    n["two"] = 22
    fmt.Println("Before n:", n, "m:", m)
    maps.Copy(m, n)
    fmt.Println("After n:", n, "m:", m)
}

 

zzh@ZZHPC:/zdata/Github/ztest$ go run main.go
map[string]int{"four":4, "one":1, "three":3, "two":2}
map[string]int{"four":4, "two":2}
Equal!
Before n: map[four:4 three:3 two:22] m: map[four:4 two:2]
After n: map[four:4 three:3 two:22] m: map[four:4 three:3 two:22]

 

标签:map,fmt,two,three,four,maps,Zgo
From: https://www.cnblogs.com/zhangzhihui/p/18241794

相关文章

  • Zgo - slices
     packagemainimport("fmt""slices")funcmain(){s1:=[]int{1,2,-1,-2}s2:=slices.Clone(s1)fmt.Printf("%p\n",s1)fmt.Printf("%p\n",s2)s1[2]=0s1[3]=0s1......
  • Zgo - csv_data.go
     packagemainimport("encoding/csv""log""os")typeRecordstruct{NamestringSurnamestringNumberstringLastAccessstring}varmyData=[]Record{}funcreadCSVFile(file......
  • Zgo - randInt, randString
     packagemainimport("fmt""math/rand""strings")const(//AsweonlywanttogetprintableASCIIcharacters,welimittherangeofpseudo-randomnumbers//thatcanbegenerated.Thetotalnumber......
  • Zgo - custom_log.go
     packagemainimport("fmt""io""log""os""path")funcmain(){flag:=os.O_APPEND|os.O_CREATE|os.O_WRONLYlogFile:=path.Join(os.TempDir(),"mGo.log")......
  • Zgo - stats.go
     packagemainimport("fmt""math""os""slices""strconv")funcmain(){args:=os.Argsiflen(args)==1{fmt.Println("Needoneormorearguments!")......
  • Zgo - which.go
     packagemainimport("fmt""os""path/filepath")funcmain(){args:=os.Argsiflen(args)==1{fmt.Println("Pleaseprovideanargument!")return}file:=args......
  • MapStruct实体映射
            具体看这个MapStruct最详细的使用教程,别在用BeanUtils.copyProperties()_mapstruct教程-CSDN博客......
  • MapStruct高级用法
    MapStruct高级用法依赖注入(Usingdependencyinjection)@Mapper(componentModel=SPRING)publicinterfaceSpringMapper{SpringMapperMAPPER=Mappers.getMapper(SpringMapper.class);PersonDTOpersonDoToDTO(Personperson);}publicstaticfinalc......
  • MapStruct的介绍及入门使用
    一、痛点  代码中存在很多JavaBean之间的转换,编写映射转化代码是一个繁琐重复还易出错的工作。使用BeanUtils工具时,对于字段名不一致和嵌套类型不一致时,需要手动编写。并且基于反射,对性能有一定开销。Spring提供的BeanUtils针对apache的BeanUtils做了很多优化,整体性能提升了不......
  • MapStruct对象映射转换
    前言2024.05.26,项目中用到了MapStruct,今天对项目中的一个实体类进行改动,发现不起作用,一顿排查下来发现是MapStruct搞错的,因此打算系统整理一下MapStruct的用法。介绍在实际开发中我们经常需要做DTO、VO、Entity对象之间的转换,在开发中常见的做法有两种:手动get、set使用Bean......