如果我错了,请纠正我,但是,我相信try块中的语句首先被执行,然后,如果发生任何异常,finally块中的语句将被执行,然后catch块中的语句被执行.如果没有发生异常,则一旦try执行块中的语句并跳过catch块中的语句,就会执行finally块中的语句.
如果我的上述概念没有错,那么我不明白为什么这段代码不起作用:
// sock is an object of the class Socket
public void run() {
try {
in = sock.getInputStream();
scan = new Scanner(in);
out = sock.getOutputStream();
pw = new PrintWriter(out);
} catch (IOException e) {
e.printStackTrace();
} finally {
sock.close();
}
}
Run Code Online (Sandbox Code Playgroud)
它仍然说我需要在finally块中包含语句try-catch.
我有一个关于 postgresql 的问题。我abc在 schema 中定义了一个枚举类型X。现在我想创建一个表,其中包含一个数据类型abc为 schema的列Y。有可能做这样的事情吗?如果是如何?
为什么下面s3和s5 String对象不同,当s5尝试在String池中创建时,它检查内容s3已经具有相同的内容,因此在字符串池中s5引用s3对象.但我的假设是错误的,那么任何人都应该纠正我.
String s1="Buggy";
String s2="Bread";
String s3="BuggyBread";
String s4 = "Buggy"+"Bread";
String s5 = s1 + s2
System.out.println(s3==s4); // True
System.out.println(s3==s5); //false
Run Code Online (Sandbox Code Playgroud) StringBuffer sb = new StringBuffer('A');
System.out.println("sb = " + sb.toString());
sb.append("Hello");
System.out.println("sb = " + sb.toString());
Run Code Online (Sandbox Code Playgroud)
输出:
sb =
sb =你好
但是,如果我传递一个字符串而不是字符,它会附加到Hello.为什么这个奇怪的行为与char?
TreeMap treemap=new TreeMap<String,double>();
treemap.put("02.00", 7.5);
treemap.put("03.30", 7.9);
treemap.put("04.00", 8.0);
treemap.put("05.30", 6.8);
treemap.put("10.00", 9.01);
treemap.put("11.30", 8.9);
treemap.put("12.00", 9.30);
System.out.println(treemap);
double min=(double) Collections.min(treemap.values());
Run Code Online (Sandbox Code Playgroud)
树图包含 - {02.00 = 7.5,03.30 = 7.9,04.00 = 8.0,05.30 = 6.8,10.00 = 9.01,11.30 = 8.9,12.00 = 9.30} min包含值:6.8
现在我想迭代键和值
treemap.put("05.30", 6.8);
Run Code Online (Sandbox Code Playgroud)
即
treemap.put("10.00", 9.01);
treemap.put("11.30", 8.9);
treemap.put("12.00", 9.30);
Run Code Online (Sandbox Code Playgroud)
并将最后三个映射键和值存储在另一个树形图中..
这是我当前的代码。
public function up()
{
Schema::table('render', function (Blueprint $table) {
$table->boolean('displayed')->default(1);
});
}`
Run Code Online (Sandbox Code Playgroud)
如何将默认值更改为0,如下所示?
public function up()
{
Schema::table('render', function (Blueprint $table) {
$table->boolean('displayed')->default(0);
});
}
Run Code Online (Sandbox Code Playgroud) java ×4
collections ×1
core ×1
enums ×1
laravel ×1
postgresql ×1
schema ×1
string ×1
treemap ×1