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

边栏推荐
- 2.常见的请求方法
- 51 independent key basic experiment
- LeetCode --- 1071. Great common divisor of strings problem solving Report
- tuple and point
- What is the most effective way to convert int to string- What is the most efficient way to convert an int to a String?
- Kbp206-asemi rectifier bridge kbp206
- Flume配置4——自定义MYSQLSource
- 8. Commodity management - commodity classification
- Eight days of learning C language - while loop (embedded) (single chip microcomputer)
- Problem solving: attributeerror: 'nonetype' object has no attribute 'append‘
猜你喜欢

Master Fur

Share the newly released web application development framework based on blazor Technology

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

2021 Li Hongyi machine learning (2): pytorch

Apache Web page security optimization

Spark SQL learning bullet 2

Elfk deployment

Simple use of devtools

Design of kindergarten real-time monitoring and control system

Azkaban overview
随机推荐
Acwing game 58 [End]
IPv6 experiment
1.五层网络模型
SQL injection exercise -- sqli Labs
Sqoop installation
College Students' innovation project management system
Ask, does this ADB MySQL support sqlserver?
Returns the lowest common ancestor of two nodes in a binary tree
D3js notes
Talk about the SQL server version of DTM sub transaction barrier function
How can we truncate the float64 type to a specific precision- How can we truncate float64 type to a particular precision?
Single box check box
When the low alcohol race track enters the reshuffle period, how can the new brand break the three major problems?
2.常见的请求方法
TCP security of network security foundation
SQL performance optimization skills
Design and implementation of community hospital information system
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
Accuracy problem and solution of BigDecimal
Breaking the information cocoon - my method of actively obtaining information - 3