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

边栏推荐
- Kbp206-asemi rectifier bridge kbp206
- Pdf things
- Ask, does this ADB MySQL support sqlserver?
- Voice chip wt2003h4 B008 single chip to realize the quick design of intelligent doorbell scheme
- 001 chip test
- Azkaban installation and deployment
- The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
- Watch the online press conference of tdengine community heroes and listen to TD hero talk about the legend of developers
- Why are there fewer and fewer good products produced by big Internet companies such as Tencent and Alibaba?
- SFTP cannot connect to the server # yyds dry goods inventory #
猜你喜欢

Pat class a 1160 forever (class B 1104 forever)

El select, El option drop-down selection box

Devtools的簡單使用
![[105] Baidu brain map - Online mind mapping tool](/img/4f/64ee0bb15aec435294d4f5fde4493e.jpg)
[105] Baidu brain map - Online mind mapping tool

About MySQL database connection exceptions

Design of kindergarten real-time monitoring and control system

Watch the online press conference of tdengine community heroes and listen to TD hero talk about the legend of developers

VM in-depth learning (XXV) -class file overview

Problem solving: attributeerror: 'nonetype' object has no attribute 'append‘

Avoid material "minefields"! Play with super high conversion rate
随机推荐
Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
Yuan universe also "real estate"? Multiple second-hand trading websites block metauniverse keywords
8. Commodity management - commodity classification
Class inheritance in C #
Cette ADB MySQL prend - elle en charge SQL Server?
SQL performance optimization skills
Devtools的簡單使用
Huawei MPLS experiment
Sqoop installation
Azkaban概述
Use UDP to send a JPEG image, and UPD will convert it into the mat format of OpenCV after receiving it
1.五层网络模型
El select, El option drop-down selection box
Linux Installation redis
2022/02/13
Last words record
LeetCode 237. Delete nodes in the linked list
College Students' innovation project management system
Why are there fewer and fewer good products produced by big Internet companies such as Tencent and Alibaba?
Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 1)