当前位置:网站首页>[groovy] string (string type variable definition | character type variable definition)
[groovy] string (string type variable definition | character type variable definition)
2022-07-05 03:12:00 【Programmer community】
List of articles
- One 、 String type variables
- Two 、 Character type variable
- 3、 ... and 、 Complete code example
One 、 String type variables
Use def Keyword declaration Groovy Medium Variable ;
Declaration string , You can use the following :
// character string // def keyword yes define abbreviation def s1 = "Hello"def s2 = 'Hello' // Single quotes are also strings def s3 = 'H' // Single quotes are also strings
Be careful : Single quotation marks and Double quotes , By default, they all represent strings ;
stay Java in , Single quotation marks are characters , If you want to declare characters , Look at the next section ;
Use println Print the above
3
3
3 The type of a variable :
// Print the types of the above three variables println s1.classprintln s2.classprintln s3.class
Complete code example :
// Groovy You can not add it before the class publicclass Test {
// Function parameter type , You don't have to state static void main(args) {
// Groovy Code may not use semicolons // println Method can call directly , Don't use System.out It's fine too // println Followed by the string to be printed Use spaces to separate , You can use no brackets println "Hello Groovy!!!" // character string // def keyword yes define abbreviation def s1 = "Hello" def s2 = 'Hello' // Single quotes are also strings def s3 = 'H' // Single quotes are also strings // Print the types of the above three variables println s1.class println s2.class println s3.class }}
Execution results : Print out the
3
3
3 Both variable types are class java.lang.String type ;
Two 、 Character type variable
In the previous chapter, we analyzed
def s3 = 'H'
Code , Used to define the string , If characters are defined , It needs to be followed by as char sentence ;
def c1 = 'H' as char
This defines a character ;
Print character and Character type variable :
// Statement char type def c1 = 'H' as char// Print character Type variable type class java.lang.Characterprintln c1println c1.class
Print the results :
3、 ... and 、 Complete code example
// Groovy You can not add it before the class publicclass Test {
// Function parameter type , You don't have to state static void main(args) {
// Groovy Code may not use semicolons // println Method can call directly , Don't use System.out It's fine too // println Followed by the string to be printed Use spaces to separate , You can use no brackets println "Hello Groovy!!!" // character string // def keyword yes define abbreviation def s1 = "Hello" def s2 = 'Hello' // Single quotes are also strings def s3 = 'H' // Single quotes are also strings // Print the types of the above three variables println s1.class println s2.class println s3.class // Statement char type def c1 = 'H' as char // Print character Type variable type class java.lang.Character println c1 println c1.class }}
Execution results :
边栏推荐
- Structure of ViewModel
- Elfk deployment
- Yyds dry goods inventory embedded matrix
- 有個疑問 flink sql cdc 的話可以設置並行度麼, 並行度大於1會有順序問題吧?
- 平台入驻与独立部署优缺点对比
- SPI and IIC communication protocol
- When the low alcohol race track enters the reshuffle period, how can the new brand break the three major problems?
- Tiny series rendering tutorial
- Pat grade a 1119 pre- and post order traversals (30 points)
- Pat class a 1162 postfix expression
猜你喜欢
看 TDengine 社区英雄线上发布会,听 TD Hero 聊开发者传奇故事
为什么腾讯阿里等互联网大厂诞生的好产品越来越少?
Ubantu disk expansion (VMware)
Azkaban实战
Design of kindergarten real-time monitoring and control system
2. Common request methods
Moco V2 literature research [self supervised learning]
2021 Li Hongyi machine learning (3): what if neural network training fails
IPv6 experiment
Pytest (4) - test case execution sequence
随机推荐
How to learn to get the embedding matrix e # yyds dry goods inventory #
为什么腾讯阿里等互联网大厂诞生的好产品越来越少?
LeetCode 237. Delete nodes in the linked list
Clean up PHP session files
[Yu Yue education] National Open University autumn 2018 8109-22t (1) monetary and banking reference questions
Asp+access campus network goods trading platform
Three line by line explanations of the source code of anchor free series network yolox (a total of ten articles, which are guaranteed to be explained line by line. After reading it, you can change the
Cette ADB MySQL prend - elle en charge SQL Server?
Yuan universe also "real estate"? Multiple second-hand trading websites block metauniverse keywords
返回二叉树中两个节点的最低公共祖先
Tiny series rendering tutorial
2021 Li Hongyi machine learning (3): what if neural network training fails
Design of KTV intelligent dimming system based on MCU
Elk log analysis system
Daily question 2 12
看 TDengine 社区英雄线上发布会,听 TD Hero 聊开发者传奇故事
FBO and RBO disappeared in webgpu
How can we truncate the float64 type to a specific precision- How can we truncate float64 type to a particular precision?
Avoid material "minefields"! Play with super high conversion rate
Pdf things