Java String

Java Java Java String


:

String str = "Runoob";

"Runoob" String

String

String str2=new String("Runoob");

String new

String s1 = "Runoob"; // String String s2 = "Runoob"; // String String s3 = s1; // String s4 = new String("Runoob"); // String String s5 = new String("Runoob"); // String

java-string-1-2020-12-01.png [java-string-1-2020-12-01.png]

String 11 :

StringDemo.java

public class StringDemo{ public static void main(String args[]){ char[] helloArray = { 'r', 'u', 'n', 'o', 'o', 'b'}; String helloString = new String(helloArray); System.out.println( helloString ); } }

runoob

:String String

StringBuffer & StringBuilder


String length()

len 14:

StringDemo.java

public class StringDemo { public static void main(String args[]) { String site = "www.runoob.com"; int len = site.length(); System.out.println( " : " + len ); } }

 : 14

String

string1.concat(string2);

string2 string1 concat()

" ".concat("Runoob");

'+'

"Hello," + " runoob" + "!"

:

"Hello, runoob!"

:

StringDemo.java

public class StringDemo { public static void main(String args[]) { String string1 = ""; System.out.println("1" + string1 + "www.runoob.com"); } }

1www.runoob.com

printf() format()

String format() String PrintStream

String format()

System.out.printf(" " + "%f, " + " %d, " + "is %s", floatVar, intVar, stringVar);

String fs; fs = String.format(" " + "%f, " + " %d, " + " %s", floatVar, intVar, stringVar);

String

String Java String API :

SN()
1 char charAt(int index)
char
2 int compareTo(Object o)
3 int compareTo(String anotherString)
4 int compareToIgnoreCase(String str)
5 String concat(String str)
6 boolean contentEquals(StringBuffer sb)
StringBuffer
7 static String copyValueOf(char[] data)
String
8 static String copyValueOf(char[] data, int offset, int count)
String
9 boolean endsWith(String suffix)
10 boolean equals(Object anObject)
11 boolean equalsIgnoreCase(String anotherString)
String String
12 byte[] getBytes()
  String byte byte
13 byte[] getBytes(String charsetName)
String byte byte
14 void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
15 int hashCode()
16 int indexOf(int ch)
17 int indexOf(int ch, int fromIndex)
18 int indexOf(String str)
 
19 int indexOf(String str, int fromIndex)
20 String intern()
 
21 int lastIndexOf(int ch)
 
22 int lastIndexOf(int ch, int fromIndex)
23 int lastIndexOf(String str)
24 int lastIndexOf(String str, int fromIndex)
 
25 int length()
26 boolean matches(String regex)
27 boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
28 boolean regionMatches(int toffset, String other, int ooffset, int len)
29 String replace(char oldChar, char newChar)
newChar oldChar
30 String replaceAll(String regex, String replacement)
replacement
31 String replaceFirst(String regex, String replacement)
  replacement
32 String[] split(String regex)
33 String[] split(String regex, int limit)
34 boolean startsWith(String prefix)
35 boolean startsWith(String prefix, int toffset)
36 CharSequence subSequence(int beginIndex, int endIndex)
 
37 String substring(int beginIndex)
38 String substring(int beginIndex, int endIndex)
39 char[] toCharArray()
40 String toLowerCase()
String
41 String toLowerCase(Locale locale)
  Locale String
42 String toString()
 
43 String toUpperCase()
String
44 String toUpperCase(Locale locale)
Locale String
45 String trim()
46 static String valueOf(primitive data type x)
data typex
47 contains(CharSequence chars)
48 isEmpty()