当前位置:网站首页>[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.classComplete 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 charThis 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.classPrint 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 :

边栏推荐
- ICSI213/IECE213 Data Structures
- Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 1)
- Character painting, I use characters to draw a Bing Dwen Dwen
- Single box check box
- Design and implementation of community hospital information system
- LeetCode 237. Delete nodes in the linked list
- Ask, does this ADB MySQL support sqlserver?
- Performance of calling delegates vs methods
- [Chongqing Guangdong education] 2777t green space planning reference questions of National Open University in autumn 2018
- [2022 repair version] community scanning code into group activity code to drain the complete operation source code / connect the contract free payment interface / promote the normal binding of subordi
猜你喜欢

Leetcode42. connect rainwater

Yyds dry goods inventory intelligent fan based on CC2530 design

Flume configuration 4 - customize mysqlsource

Linux安装Redis

Azkaban概述

1. Five layer network model

Azkaban安装部署

Ubantu disk expansion (VMware)

Asemi rectifier bridge 2w10 parameters, 2w10 specifications, 2w10 characteristics

Azkaban actual combat
随机推荐
看 TDengine 社区英雄线上发布会,听 TD Hero 聊开发者传奇故事
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
What is the most effective way to convert int to string- What is the most efficient way to convert an int to a String?
Elfk deployment
Azkaban安装部署
Problem solving: attributeerror: 'nonetype' object has no attribute 'append‘
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
GFS distributed file system
[deep learning] deep learning reference materials
Design and implementation of community hospital information system
ICSI213/IECE213 Data Structures
[105] Baidu brain map - Online mind mapping tool
Design of KTV intelligent dimming system based on MCU
8. Commodity management - commodity classification
College Students' innovation project management system
問下,這個ADB mysql支持sqlserver嗎?
Cette ADB MySQL prend - elle en charge SQL Server?
2021 Li Hongyi machine learning (1): basic concepts
有個疑問 flink sql cdc 的話可以設置並行度麼, 並行度大於1會有順序問題吧?
Zabbix