我对Java并不太新,虽然我以前从未真正使用过Set
s,所以有人可以帮助我吗?
我有以下问题; 但首先,这是我的代码:
HashMap<Position[], String> save = io.getSave();
Position[][] saved_pos = (Position[][]) save.keySet().toArray();
Run Code Online (Sandbox Code Playgroud)
虽然在第二行,Java抛出了ClassCastException
,但为什么呢?显然,返回的Array save.keySet().toArray()
确实包含Position[][]
s,尽管不幸的是,toArray()
在类Set
中只返回一个Object[]
数组.
那么我能做什么,我需要投这个.
我正在创建一个连接多个数据库的Java应用程序。用户将能够从下拉框中选择要连接的数据库。
然后,该程序将名称传递给创建初始上下文的方法,从而连接到数据库,从而可以与oracle Web逻辑数据源进行通讯。
public class dbMainConnection {
private static dbMainConnection conn = null;
private static java.sql.Connection dbConn = null;
private static javax.sql.DataSource ds = null;
private static Logger log = LoggerUtil.getLogger();
private dbMainConnection(String database) {
try {
Context ctx = new InitialContext();
if (ctx == null) {
log.info("JDNI Problem, cannot get InitialContext");
}
database = "jdbc/" + database;
log.info("This is the database string in DBMainConnection" + database);
ds = (javax.sql.DataSource) ctx.lookup (database);
} catch (Exception ex) {
log.error("eMTSLogin: Error in …
Run Code Online (Sandbox Code Playgroud) 我正在尝试根据第二次出现的符号将字符串拆分为数组 _
var string = "this_is_my_string";
Run Code Online (Sandbox Code Playgroud)
我想在第二个下划线之后拆分字符串.字符串并不总是相同,但它总是有2个或更多下划线.我总是需要将它拆分为第二个下划线.
在上面的示例字符串中,我需要像这样拆分它.
var split = [this_is, _my_string];
Run Code Online (Sandbox Code Playgroud) 我认为我完全有许多变量,但我完全没有它们,因为它们对于接收POST数据的控制器都是至关重要的.
它破坏了tv:tv,PHP Eclipse将其变为红色,但并没有告诉我问题是什么.Chromes控制台说出了意想不到的标识符.这里发生了什么?
我在这些问题中到处寻找,我找不到这样的东西.
我该如何解决它仍然使用所有这些表单字段?
$.ajax({
type: 'POST',
url: $('.pa-details-submit ul li a').attr('href'),
data: {
make_active_check: make_active_check,
details_title: details_title,
details_country: details_country,
details_desc: details_desc,
details_price: details_price,
details_zipcode: details_zipcode,
details_state: details_state,
details_city: details_city,
details_add: details_add,
details_hidden: details_hidden,
featured: featured,
bedrooms: bedrooms,
baths: baths,
beds: beds,
floor: floor,
sleeps: sleeps,
couches: couches,
door: door,
laundry: laundry,
dishwasher: dishwasher,
furnished: furnished,
elevator: elevator,
mon: mon,
tue: tue,
wed: wed,
thu: thu,
fri: fri,
sat: sat,
sun: sun,
pets_allowed: pets_allowed,
cabletv: cabletv,
tv: tv,
wireless_net, …
Run Code Online (Sandbox Code Playgroud) 有一个整数列表
List<Integer> l = new ArrayList<Integer>();
Run Code Online (Sandbox Code Playgroud)
我认为调用l.contains
很慢,如何对列表进行排序.排序后,会l.contains
表现得更快吗?
有没有我可以直接使用的sortedList?
为什么在其构造函数中实例化同类的对象会抛出StackOverflowError
?例如 ,
public class A {
public A () {
A a = new A()
}
}
Run Code Online (Sandbox Code Playgroud)
会抛出StackOverFlowError
?
private String setDate(int day) {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, + day);
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
String formattedDate = df.format(cal.getTime());
return formattedDate;
}
Run Code Online (Sandbox Code Playgroud)
上述方法返回"14/06/12" Locale.UK
和"06/14/12" Locale.US
.
我怎样才能让它全年返回,即"14/06/2012"为美国语言环境,"06/14/2012"为英国语言环境?
以下程序失败:
abstract class A {
protected void method() {}
}
class B extends A {
private void method() {}
}
public class main{
public static void main(String []args) {}
}
Run Code Online (Sandbox Code Playgroud)
有:
main.java:6: error: method() in B cannot override method() in A
private void method() {}
^
attempting to assign weaker access privileges; was protected
1 error
Run Code Online (Sandbox Code Playgroud)
将派生方法设置为protected/private.
问题:Java不允许您进一步限制子类中的访问权限的原因是什么?我将此与C++形成对比,C++具有完全相反的规则.
var settings = {};
$(".js-gen-settings").each(function(){
var date;
if (($(this).attr("type") === "checkbox") || ($(this).attr("type") === "radio")){//if its a checkbox
eval("settings."+this.name+" = "+$(this).is(":checked"));
}else{
date = $(this).val();
if (date == ""){
eval("settings." + this.name + " = null");
}else{
eval("settings." + this.name + " = '" + date + "'");
}
}
});
Run Code Online (Sandbox Code Playgroud)
将使用ajax将一个JSON.stringify
版本settings
发送到服务器.
我刚才在一本书上读到了这段代码。
public class AdapterWrapper implements ListAdapter {
ListAdapter delegate=null;
// other code
}
Run Code Online (Sandbox Code Playgroud)
这ListAdapter
是一个公共接口,并且已创建该接口的引用并将其分配为 null。这是有效的吗?我对此真的很困惑。
java ×7
javascript ×2
jquery ×2
ajax ×1
android ×1
casting ×1
class ×1
constructor ×1
date ×1
date-format ×1
eval ×1
exception ×1
inheritance ×1
interface ×1
jdbc ×1
json ×1
oop ×1
oracle ×1
reference ×1
weblogic ×1