我有一些我想知道的问题.我知道字符串在Java中是不可变的,因此在分配给现有字符串对象时会创建新的字符串对象而不是更改.
现在问我的问题.我们假设我有以下代码:
String a = "Hello World";
String b = "Hello World";
String res = a.substring(0,4) + b.substring(6,10);
Run Code Online (Sandbox Code Playgroud)
第3行的代码将创建多少个字符串对象?每次调用substring都会创建一个新的字符串对象吗?我上面的代码会生成3个新的字符串对象吗?
提前致谢
我有一个问题,我需要帮助.我有一个HashSet包含char[].问题是我无法使用该方法检查是否存在值contains(),即使该值存在,它也会返回false HashSet.
我该如何解决这个问题?
我在解决这个问题上遇到了很大的问题.我正在尝试使用Datetime.ParseExact()解析字符串.
我有以下代码:
DateTime.ParseExact("20151210 832", "yyyyMMdd Hmm", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
mscorlib.dll中发生未处理的"System.FormatException"类型的异常附加信息:String未被识别为有效的DateTime.
我究竟做错了什么?我怎么解决这个问题?
更新:
我也可以得到这样的时间:
00:01 => 1
01:00 => 1
01:10 => 10
Run Code Online (Sandbox Code Playgroud) 我需要帮助来制定查询.我想从表A和表B中选择所有DISTINCT颜色.
这是查询的结果:
BLACK
RED
YELLOW
BLUE
Run Code Online (Sandbox Code Playgroud)
我有这些表:
表A.
ID NAME COLOR
5 SOCKS BLACK
4 SOCKS RED
Run Code Online (Sandbox Code Playgroud)
表B
ID NAME COLOR
0 CAR BLUE
1 BIKE BLUE
5 TRUCK YELLOW
10 PLANE NULL
Run Code Online (Sandbox Code Playgroud)
我试过了:
SELECT DISTINCT A.color FROM A JOIN B ON b.color
Run Code Online (Sandbox Code Playgroud)
但我没有得到所有的颜色.:(
我在使用 gson 库时遇到了大麻烦。在构建项目时,我得到:
“无法解析符号gson”
我已经用谷歌搜索了几个小时,但似乎没有解决方案。这是我的 build.gradle 文件:
android {
compileSdkVersion 24
buildToolsVersion "28.0.2"
defaultConfig {
applicationId "com.example.jasminkrhan.vaktija"
minSdkVersion 24
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.8.2'
}
Run Code Online (Sandbox Code Playgroud)
还有我的 build.gradle 项目文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript …Run Code Online (Sandbox Code Playgroud)