티스토리 뷰
String class in java
- case sensitive (lower case gives an error)
- no need 'new' keyword
- It restricts the creation of a string instance consisting of the same string.
- It does not allow changes to the data in the String instance.
If you want to make variables that hold the strings, you need to create object first.
1 2 3 4 5 6 7 | class Student { public static void main(String[] args) { String hello = new String("Hello Java") // use 'new' keyword to create new object } } | cs |
Luckily we do not need 'new' keyword when we use String class. Java made it easier because we use it a lot
1 2 3 4 5 6 7 8 | class Student { public static void main(String[] args) { String hello = String("Hello Java"); System.out.println(hello); } } | cs |
no need to initialize it immediately. We can use it like primitive data types.
1 2 3 4 5 6 7 8 9 10 | class Student { public static void main(String[] args) { String hello; hello = "Hello Java "; System.out.println(hello); } } | cs |
String hello = ""; // preferred way to initialize. It has zero characters and it is doing an operation on it,
String hello = null; // no references to it, therefore, it will give you NPE(NullPointerException)
Reference
https://www.edureka.co/blog/java-string/
https://www.w3resource.com/java-tutorial/exploring-methods-of-string-class.php
https://www.geeksforgeeks.org/different-ways-for-integer-to-string-conversions-in-java/
'JAVA' 카테고리의 다른 글
What's the difference between two different List declaration? (0) | 2019.02.02 |
---|---|
Upcasting (Object type casting) in java (0) | 2019.01.30 |
Collection framework - ArrayList (0) | 2019.01.17 |
abstract & Interface in java (0) | 2019.01.17 |
toString method (0) | 2019.01.08 |
- Total
- Today
- Yesterday
- code refactoring
- Javascript Algorithm
- math.abs
- easy algorithm
- rest parameter
- 프로그래머스
- 알고리즘
- hackerrank
- hackerrank solution
- HackerRank Algorithm
- hackerrank javascript solution
- C++
- algorithm
- java
- string class in java
- 프로그래머스 알고리즘
- hackerrank javascript
- ... in Javascript
- repeat()
- javascript
- easy javascript algorithm
- HashMap
- spring boot application
- math.max
- 프로그래머스 알고리즘문제
- Collection Framework
- compareTo()
- Object type casting
- substring()
- equals()
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |