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

边栏推荐
- Talk about the SQL server version of DTM sub transaction barrier function
- 1. Five layer network model
- Apache build web host
- Qrcode: generate QR code from text
- Good documentation
- 040. (2.9) relieved
- Flume配置4——自定义MYSQLSource
- Bumblebee: build, deliver, and run ebpf programs smoothly like silk
- The latest blind box mall, which has been repaired very popular these days, has complete open source operation source code
- Azkaban actual combat
猜你喜欢

The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety

SPI and IIC communication protocol

Character painting, I use characters to draw a Bing Dwen Dwen

Design and implementation of community hospital information system

Tiny series rendering tutorial

Single box check box

Yyds dry goods inventory intelligent fan based on CC2530 design

el-select,el-option下拉选择框

Vb+access hotel service management system

The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
随机推荐
Spark SQL learning bullet 2
Design and implementation of high availability website architecture
Sqoop安装
Utilisation simple de devtools
[Yu Yue education] National Open University autumn 2018 8109-22t (1) monetary and banking reference questions
Elk log analysis system
Leetcode92. reverse linked list II
Azkaban installation and deployment
Yyds dry goods inventory intelligent fan based on CC2530 design
Last words record
VM in-depth learning (XXV) -class file overview
Apache Web page security optimization
GFS分布式文件系统
[Chongqing Guangdong education] 2777t green space planning reference questions of National Open University in autumn 2018
Pytest (4) - test case execution sequence
Sqoop command
d3js小记
1. Five layer network model
Anchor free series network yolox source code line by line explanation Part 2 (a total of 10, ensure to explain line by line, after reading, you can change the network at will, not just as a participan
Voice chip wt2003h4 B008 single chip to realize the quick design of intelligent doorbell scheme