---
title: Java
shortTitle:
category:
- Java
tag:
- &
description: Java String JavaStringJava
head:
- - meta
- name: keywords
content: Java, String, ,
---
String Java String
String
- String [final ](https://javabetter.cn/oo/final.html)[](https://javabetter.cn/basic-extra-meal/override-overload.html)
- String `char[]` final String
```java
public final class String
implements java.io.Serializable, Comparable, CharSequence {
/** The value is used for character storage. */
private final char value[];
}
```
String
Java String User String getUserCredentials
```java
class User {
private String username;
private String password;
public User(String username, String password) {
this.username = username;
this.password = password;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
}
public class StringSecurityExample {
public static void main(String[] args) {
String username = "";
String password = "123456";
User user = new User(username, password);
//
String[] credentials = getUserCredentials(user);
// getUserCredentials
credentials[0] = "";
credentials[1] = "612311";
// User
System.out.println(": " + user.getUsername());
System.out.println(": " + user.getPassword());
}
public static String[] getUserCredentials(User user) {
String[] credentials = new String[2];
credentials[0] = user.getUsername();
credentials[1] = user.getPassword();
return credentials;
}
}
```
getUserCredentials User String
[](https://javabetter.cn/collection/hashmap.html)
String
```java
String text1 = "";
String text2 = "";
// text1
int hashCode1 = text1.hashCode();
System.out.println(" text1 : " + hashCode1);
// text1
int hashCode1Cached = text1.hashCode();
System.out.println(": " + hashCode1Cached);
// text2 text1 text2
//
int hashCode2 = text2.hashCode();
System.out.println("text2 : " + hashCode2);
```
text1 text2 text1 text1 text2
String String String
[](https://javabetter.cn/string/constant-pool.html)Java String
String
`substring()`
```java
public String substring(int beginIndex) {
if (beginIndex < 0) {
throw new StringIndexOutOfBoundsException(beginIndex);
}
int subLen = value.length - beginIndex;
if (subLen < 0) {
throw new StringIndexOutOfBoundsException(subLen);
}
return (beginIndex == 0) ? this : new String(value, beginIndex, subLen);
}
```
`substring()` new
`concat()`
```java
public String concat(String str) {
int olen = str.length();
if (olen == 0) {
return this;
}
if (coder() == str.coder()) {
byte[] val = this.value;
byte[] oval = str.value;
int len = val.length + oval.length;
byte[] buf = Arrays.copyOf(val, len);
System.arraycopy(oval, 0, buf, val.length, oval.length);
return new String(buf, coder);
}
int len = length();
byte[] buf = StringUTF16.newBytesFor(len + olen);
getBytes(buf, 0, UTF16);
str.getBytes(buf, len, UTF16);
return new String(buf, UTF16);
}
```
`concat()`
`replace()`
****
String String
---
GitHub 17000+ [ Java ](https://github.com/itwanger/toBeBetterJavaer) PDF Java&OOPJava IOJava NIOJVM 32 500+[GitHub 17000+ Java ](https://javabetter.cn/overview/)
**** **222**
