์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- ์คํ๋ง์ํ๋ฆฌํฐ ๋ก๊ทธ์์
- ์ฐ์ฐ์
- ๋ฐ๋ณต๋ฌธ
- StringBuffer
- ์ฐ์ ์ฐ์ฐ์
- ์ค๋ฒ๋ก๋ฉ
- SQLํ๋
- ์ดํด๋ฆฝ์ค ์ค์น
- ๊ฐ์ฒด
- SQL
- ๋ ผ๋ฆฌ ์ฐ์ฐ์
- ํจ์
- join
- ์ค๋ฒ๋ผ์ด๋ฉ
- SpringSecurity ๋ก๊ทธ์ธ
- ๋ฐฐ์ด
- ์๋ฐ์์ ์
- ์น์ ํ SQL
- ์น์ ํ SQL ํ๋
- ์์
- ๊ฐ์ฒด์งํฅ
- SpringSecurity ๋ก๊ทธ์์
- ๋น๊ต ์ฐ์ฐ์
- @PreAuthorize("isAuthenticated()")
- SQL ํ๋
- ์๋ณ์
- ์ธํ ๋ฆฌ์ ์ด Web ์ ํ๋ฆฌ์ผ์ด์
- ์์ฝ์ด
- spring ๊ฒ์ํ ์ญ์
- java
- Today
- Total
gi_dor
Java System , String ๋ณธ๋ฌธ
๐ ๊ตญ๋น 22 ์ผ์ฐจ
๐ธ System ํด๋์ค
- Java ์คํํ๊ฒฝ์ด ์ค์น๋ ์์คํ (์ปดํจํฐ)์ ๋ํ ๊ฐ๊ณผ ๊ฐ์ฒด๋ฅผ ์ ๊ณตํ๋ ํด๋์ค
- java.lang ํจํค์ง์ ์ํด์๋ค
- Systemํด๋์ค์ ๋ชจ๋ ํ๋์ ๋ชจ๋ ๋ฉ์๋๋ ์ ์ ํ๋ , ์ ์ ๋ฉ์๋๋ค
- ์ ๊ณต ํ๋ ๊ฒ
ํ์ค ์ ๋ ฅ์ฅ์น , ์ถ๋ ฅ์ฅ์น , ์๋ฌ์ถ๋ ฅ์ฅ์น์ ์ฐ๊ฒฐ๋ ์คํธ๋ฆผ
์ปดํจํฐ ํ๊ฒฝ๋ณ์ , ํ๋กํผํฐ ๊ฐ
์ปดํจํฐ ํ์ฌ์๊ฐ ์ ๋ณด ์ ๊ณต
package lang;
import java.util.Properties;
public class SystemApp1 {
public static void main(String[] args) {
/*
* long currentTimeMillis()
* ์ ๋์ค ํ์์ 1970๋
1์1์ผ0์0๋ถ0์ด๋ถํฐ ํ์ฌ๊น์ง์ ์๊ฐ์
* 1 /1000 ๋จ์๋ก ํํํ ๊ฒ
*/
long unixTime = System.currentTimeMillis();
System.out.println("์ ๋์คํ์ : "+ unixTime);
Properties props = System.getProperties();
System.out.println(props);
/*
* String getProperty(String name)
*
*/
String value1 = System.getProperty("user.language");
String value2 = System.getProperty("user.country");
String value3 = System.getProperty("user.name");
String value4 = System.getProperty("user.home");
String value5 = System.getProperty("user.dir");
System.out.println("์ธ์ด : " + value1);
System.out.println("๊ตญ๊ฐ : " + value2);
System.out.println("์ฌ์ฉ์ ์ด๋ฆ: " + value3);
System.out.println("ํ ๋๋ ํ ๋ฆฌ ๊ฒฝ๋ฌ : " + value4);
System.out.println("ํ์ฌ ๋๋ ํ ๋ฆฌ : " + value5);
// ์ธ์ด : ko
// ๊ตญ๊ฐ : KR
// ์ฌ์ฉ์ ์ด๋ฆ: Han
// ํ ๋๋ ํ ๋ฆฌ ๊ฒฝ๋ฌ : C:\Users\Han
// ํ์ฌ ๋๋ ํ ๋ฆฌ : C:\workspace\Java-workspace\api
/*
* System.getenv(String name)
* ์ง์ ๋ ์ด๋ฆ์ ํด๋นํ๋ ํ๊ฒฝ ๋ณ์ ๊ฐ ๋ฐํ
*/
String env1 = System.getenv("JAVA_HOME");
String env2 = System.getenv("PATH");
String env3 = System.getenv("TEMP");
System.out.println("์๋ฐ ํ ๋๋ ํ ๋ฆฌ : "+env1);
// ์๋ฐ ํ ๋๋ ํ ๋ฆฌ : C:\Program Files\Java\jdk-17
System.out.println("path ์ค์ ๋ ๊ฒฝ๋ก : "+env2);
System.out.println("์์ ๋๋ ํ ๋ฆฌ ๊ฒฝ๋ก : "+env3);
// ์์ ๋๋ ํ ๋ฆฌ ๊ฒฝ๋ก : C:\Users\Han\AppData\Local\Temp
}
}
๐ธ String
- ๋ฌธ์์ด์ ํํํ๋ ๊ฐ์ฒด
- ๋ฌธ์์ด String์ ๋ถ๋ณ ๊ฐ์ฒด๋ค โถ ํ๋ฒ ์์ฑ๋ ๋ฌธ์์ด์ ์ ๋๋ก ๋ณํ์ง ์๋๋ค
- String ๊ฐ์ฒด์์ฑ
String s = "abc";
String s = new String("abc");
char[] data = {'a', 'b', 'c'};
String s = new String(data);
String๊ฐ์ฒด๋ ๋ฌธ์์ด๊ณผ ๊ด๋ จ๋ ๋ค์ํ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ค
๐น String ์ฃผ์ ๋ฉ์๋
- int length ( )
- ๋ฌธ์์ด์ ๊ธธ์ด๋ฅผ ๋ฐํ
String s3 = "์๋
ํ์ธ์";
String s4 = "";
String s5 = " ";
System.out.println("๊ธธ์ด1 : " + s3.length()); // 5
System.out.println("๊ธธ์ด1 : " + s4.length()); // 0
- boolean equals (Objecct str)
- ๋ / ์๋ฌธ์ ๊ตฌ๋ถํ๋ค
- ์ง์ ๋ ๋ฌธ์์ด๊ณผ ๋ฌธ์์ด์ ๋ด์ฉ์ ๋น๊ตํด์ ์ผ์นํ๋ฉด true ๋ฐํ
- ๋ฌธ์์ด์ '๋ด์ฉ'์ ๋น๊ต
String str1 = "๊น๋นต๋นต";
String str2 = "๊น๋นต๋นต";
String str3 = new String("๊น๋นต๋นต");
String str4 = new String("๊น๋นต๋นต");
System.out.println("์ฃผ์๊ฐ ๋น๊ต : " + (str1 == str2)); // true
System.out.println("์ฃผ์๊ฐ ๋น๊ต : " + (str3 == str4)); // false
System.out.println("์ฃผ์๊ฐ ๋น๊ต : " + (str1 == str3)); // false
System.out.println("๋ฌธ์์ด ๋ด์ฉ๋น๊ต : " + str1.equals(str2)); // true
System.out.println("๋ฌธ์์ด ๋ด์ฉ๋น๊ต : " + str3.equals(str4)); // true
System.out.println("๋ฌธ์์ด ๋ด์ฉ๋น๊ต : " + str1.equals(str3)); // true
- boolean equalsIgnoreCase(String str)
- ๋/์๋ฌธ์ ๊ตฌ๋ถํ์ง ์๊ณ ๋น๊ต
- ๋ฌธ์์ด ๋ด์ฉ๋น๊ต ๋๋ฑ์ฑ ์ฌ๋ถ ๋ฐํ
String str5 = "Hello";
String str6 = "hello";
System.out.println("๋์๋ฌธ์ ๋ฌด์ : " + str5.equalsIgnoreCase(str6)); // true
System.out.println("๋์๋ฌธ์ ๊ตฌ๋ถ : " + str5.equals(str6)); // false
- boolean ieEmpty()
- ๋ฌธ์์ด ๊ธธ์ด๊ฐ 0์ธ๊ฒฝ์ฐ true๋ฐํ
- ๊ธธ์ด๊ฐ 0 ์ธ ๋ฌธ์์ด
- " "
String str1 = "";
String str2 = " ";
String str3 = "abc";
boolean result1 = str1.isEmpty(); // true
boolean result2 = str2.isEmpty(); // false
boolean result3 = str3.isEmpty(); // false
- boolean contains(CharSequence s)
- ์ง์ ๋ ๋ฌธ์์ด์ด ํฌํจ๋์ด ์์ผ๋ฉด true๋ฐํ
String str6 = "ERP ์ฝํผ๋ ์ด์
";
System.out.println("๋ฌธ์์ด์ ํฌํจํ๋๊ฐ : " + str6.contains("์ฝํผ")); // true
- int indexOf(String str)
- ์ง์ ๋ ๋ฌธ์์ด์ด ์ฒ์์ผ๋ก ๋ฑ์ฅํ๋ ์์น๋ฐํ
- ์ฐพ์์ ์์ผ๋ฉด -1 ๋ฐํ
String str = "My car is red car";
int index = str.indexOf("car"); // 3
- int lastIndexOf(String str)
- ์ง์ ๋ ๋ฌธ์์ด์ด ๋ง์ง๋ง์ผ๋ก ๋ฑ์ฅํ๋ ์์น๋ฐํ
String str = "My car is red car";
int index = str.lastiIndexOf("car"); // 14
- String substring(int beginIndex)
- ์ง์ ๋ ์์์์น ~ ๋์์น ๋ฒ์์ ํด๋นํ๋ ๋ฌธ์์ด์ ์๋ก ๋ง๋ค์ด์ ๋ฐํ
- ์ธ๋ฑ์ค๋ 0๋ถํฐ ์์
String str1 = "ERP ์ฝํผ๋ ์ด์
";
String str2 = str1.substring(2);
String str3 = str1.substring(2, 6);
System.out.println(str2); // P ์ฝํผ๋ ์ด์
System.out.println(str3); // P ์ฝํผ
String str4 = "000305 - 3333852";
String str5 = str4.substring(0, 2);
System.out.println("ํ์ด๋ํด : " + str5 + " ๋
์"); // ํ์ด๋ํด : 00 ๋
์
String str6 = str4.substring(2, 6);
System.out.println("์์ผ : " + str6); // ์์ผ : 0305
- String replace(String searchStr, String replaceStr)
- searchStr์ ํด๋นํ๋ ๋ฌธ์์ด์ด replaceStr๋ก ๋์ฒด๋ ์๋ฌธ์์ด์ ๋ฐํํ๋ค
String str4 = "The red House's color is red";
String str5 = str4.replace("red", "Gray");
System.out.println("์๋ณธ ๋ฌธ์์ด : " + str4); // ์๋ณธ ๋ฌธ์์ด : The red House's color is red
System.out.println("์๋ก์ด ๋ฌธ์์ด : " + str5); // ์๋ก์ด ๋ฌธ์์ด : The Gray House's color is Gray
- String replaceAll(String regex , String replacement)
- ๋ฌธ์์ด์์ ์ง์ ๋ ์ ๊ทํํ์ ํจํด์ ํด๋นํ๋ ๋ถ๋ถ์ replacement ์์ ์ง์ ํ ๋ฌธ์์ด์ ์ ๋ฌธ์์ด๋ก ๋ฐํ
String str6 = "Red house's color is red";
String str7 = str6.replace("red", "green");
String str8 = str6.replaceAll("/red/i", "green");
System.out.println("์๋ก์ด ๋ฌธ์์ด : " + str7); // Red house's color is green
System.out.println("์๋ก์ด ๋ฌธ์์ด : " + str8); // Red house's color is red
- String toLowerCase()
- ๋ฌธ์์ด์ ์๋ฌธ์๋ก ์๋ก ๋ง๋ค์ด์ ๋ฐํ
String str1 = "Hello Eclipse";
String str3 = str1.toLowerCase();
System.out.println("์๋ณธ ๋ฌธ์์ด : " + str1); // ์๋ณธ ๋ฌธ์์ด : Hello Eclipse
System.out.println("์๋ก์ด ๋ฌธ์์ด : " + str3); // ์๋ก์ด ๋ฌธ์์ด : hello eclipse
- String toUpperCase()
- ๋ฌธ์์ด์ ๋๋ฌธ์๋ก ์๋ก๋ง๋ค์ด์ ๋ฐํ
String str1 = "Hello Eclipse";
String str2 = str1.toUpperCase();
System.out.println("์๋ณธ ๋ฌธ์์ด : " + str1); // ์๋ณธ ๋ฌธ์์ด : Hello Eclipse
System.out.println("์๋ก์ด ๋ฌธ์์ด : " + str2); // ์๋ก์ด ๋ฌธ์์ด : HELLO ECLIPSE
- String trim()
- ๋ฌธ์์ด์ ์ข์ฐ ๋ถํ์ํ ๊ณต๋ฐฑ์ด ์ ๊ฑฐ๋ ์๋ก์ด ๋ฌธ์์ด์ ๋ง๋ค์ด์ ๋ฐํ
/*
* String strip()
* ` ๋ฌธ์์ด์์ ๋ถํ์ํ ์ข์ฐ ๊ณต๋ฐฑ์ด ์ ๊ฑฐ๋ ์๋ฌธ์์ด์ ๋ฐํ
*
* String stripLeading()
* ` ๋ฌธ์์ด์์ ์ผ์ชฝ ๊ณต๋ฐฑ์ด ์ ๊ฑฐ๋ ์ ๋ฌธ์์ด ๋ฐํ
*
* String stripTrailing()
* ` ๋ฌธ์์ด์์ ์ค๋ฅธ์ชฝ ๊ณต๋ฐฑ์ด ์ ๊ฑฐ๋ ์ ๋ฌธ์์ด ๋ฐํ
*/
String str9 = " ๋ฐ๊ฐ ์ต๋๋ค ์
๋๋ค ";
String str10 = str9.trim();
String str11 = str9.strip();
String str12 = str9.stripLeading();
String str13 = str9.stripTrailing();
System.out.println("์๋ณธ ๋ฌธ์์ด : [" + str9 + "]"); // ์๋ณธ ๋ฌธ์์ด : [ ๋ฐ๊ฐ ์ต๋๋ค ์
๋๋ค ]
System.out.println("์๋ก์ด ๋ฌธ์์ด1 : [" + str10 + "]"); // ์๋ก์ด ๋ฌธ์์ด1 : [๋ฐ๊ฐ ์ต๋๋ค ์
๋๋ค]
System.out.println("์๋ก์ด ๋ฌธ์์ด2 : [" + str11 + "]"); // ์๋ก์ด ๋ฌธ์์ด2 : [๋ฐ๊ฐ ์ต๋๋ค ์
๋๋ค]
System.out.println("์๋ก์ด ๋ฌธ์์ด3 ์ผ์ชฝ ๊ณต๋ฐฑ์ ๊ฑฐ: [" + str12 + "]"); // ์๋ก์ด ๋ฌธ์์ด3 ์ผ์ชฝ ๊ณต๋ฐฑ์ ๊ฑฐ: [๋ฐ๊ฐ ์ต๋๋ค ์
๋๋ค ]
System.out.println("์๋ก์ด ๋ฌธ์์ด4 ์ค๋ฅธ์ชฝ ๊ณต๋ฐฑ์ ๊ฑฐ: [" + str13 + "]"); // ์๋ก์ด ๋ฌธ์์ด4 ์ค๋ฅธ์ชฝ ๊ณต๋ฐฑ์ ๊ฑฐ: [ ๋ฐ๊ฐ ์ต๋๋ค ์
๋๋ค]
- boolean startsWith(String Prefix)
- ๋ฌธ์์ด์ด ์ง์ ๋ prefix๋ฅผ ์์ํ๊ณ ์๋ค๋ฉด true ๋ฐํ
String str7 = "http://projectSyuSyu/syusyu/notice";
String str8 = "https://localhost/8080/intdex.html";
String str9 = "https://kmooc.udemy.com/organization/home/";
System.out.println("๋ฌธ์์ด์ด https ์์ ํ๋๊ฐ :" + str7.startsWith("https")); // false
System.out.println("๋ฌธ์์ด์ด https ์์ ํ๋๊ฐ :" + str8.startsWith("https")); // true
System.out.println("๋ฌธ์์ด์ด http ์์ ํ๋๊ฐ :" + str9.startsWith("http")); // false
- boolean endsWith(String suffix)
- ๋ฌธ์์ด์ด ์ง์ ๋ suffix๋ก ๋๋๋ฉด true ๋ฐํ
String str10 = "sample.hwp";
String str11 = "sample2.xlsx";
String str12 = "sample.xml";
System.out.println("์์
ํ์ผ์ธ๊ฐ ? : " + str10.endsWith("xlsx")); // false
System.out.println("์์
ํ์ผ์ธ๊ฐ ? : " + str11.endsWith("xlsx")); // true
System.out.println("์์
ํ์ผ์ธ๊ฐ ? : " + str12.endsWith("xlsx")); // false
- String [] split(String regax)
- ๋ฌธ์์ด์ ์ง์ ๋ ๊ตฌ๋ถ ๋ฌธ์์ด๋ก ์๋ผ์ ๊ฐ๊ฐ์์๋ฅผ ๋ฐฐ์ด์ ๋ด์ ๋ฐํ
String str = "๊ณฝ์ฌ์ฐ,๊น์ ์ ,๊น์๋ฏผ,์๊ถ,ํ์ฌ์";
String[] result = str.split(",");
// ์ถ๋ ฅ 1๋ฒ๋ฐฉ๋ฒ
System.out.println(result[0]);
System.out.println(result[1]);
System.out.println(result[2]);
System.out.println(result[3]);
System.out.println(result[4]);
// ์ถ๋ ฅ 2๋ฒ๋ฐฉ๋ฒ
System.out.println(Arrays.toString(result)); // [๊ณฝ์ฌ์ฐ, ๊น์ ์ , ๊น์๋ฏผ, ์๊ถ, ํ์ฌ์]
// ์ถ๋ ฅ 3๋ฒ ๋ฐฉ๋ฒ
for (String value : result) {
System.out.println(value);
}
- int comapareTo(String other)
- ์ง์ ๋ ๋ค๋ฅธ๋ฌธ์์ ์ฌ์ ์์๋๋ก ๋น๊ต
- ๋ฐฐ์ด์ด๋ ์ปฌ๋ ์ ์ ์ ์ฅ๋ ๋ฌธ์์ด์ ์ ๋ ฌํ ๋ ์ฌ์ฉ
String a = "apple";
String b = "banana";
int result = a.compareTo(b); // ๋ฐํ ๊ฐ์ผ๋ก -1 0 ์์์ ์ ์ถ๋ ฅ
System.out.println(result); // -1
- char charAt(int index)
- ๋ฌธ์์ด์์ ์ง์ ๋ ์์น์ ๊ธ์ ํ๋๋ฅผ ๋ฌธ์๋ก ๋ฐํ
String str = "abc";
char c = str.charAt(0); // 'a'
- static String valueOf(๋ค์ํ ๊ฐ)
- ์ ๋ฌ๋ฐ์ ๋ค์ํ ํ์ ์ ๊ฐ์ ๋ฌธ์์ด๋ก ๋ฐ๊ฟ์ ๋ฐํ
- ์ ์ ๋ฉ์๋
String result1 = String.valueOf(10); // "10"
String result2 = String.valueOf(3.14); // "3.14"
String result3 = String.valueOf(true); // "true"
'Language > Java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Java Random , Math (0) | 2023.11.16 |
---|---|
Java Wrapper , Date , Calendar , StringBuilder , Buffer (6) | 2023.11.15 |
Java final , Object , toString (1) | 2023.11.13 |
Java (6) ๊ฐ์ฒด์งํฅ - ์ ๊ทผ์ ์ด์ , ๋ด๋ถํด๋์ค (0) | 2023.11.13 |
Java (6) ๊ฐ์ฒด์งํฅ - ์ค๋ฒ๋ผ์ด๋ฉ , ๋คํ์ฑ , ์ถ์ํ , ์ธํฐํ์ด์ค (0) | 2023.11.09 |