我已经看到了如何在SO中为零添加前缀的问题.但不是其他方式!
你们可以建议我如何删除字母数字文本中的前导零?是否有任何内置API或我是否需要编写方法来修剪前导零?
例:
01234 converts to 1234
0001234a converts to 1234a
001234-a converts to 1234-a
101234 remains as 101234
2509398 remains as 2509398
123z remains as 123z
000002829839 converts to 2829839
Run Code Online (Sandbox Code Playgroud) 如何在应用程序上下文中读取系统环境变量?
我想要的东西:
<util:properties id="dbProperties"
location="classpath:config_DEV/db.properties" />
Run Code Online (Sandbox Code Playgroud)
要么
<util:properties id="dbProperties"
location="classpath:config_QA/db.properties" />
Run Code Online (Sandbox Code Playgroud)
取决于环境.
我的应用程序上下文中可以有这样的东西吗?
<util:properties id="dbProperties"
location="classpath:config_${systemProperties.env}/db.properties" />
Run Code Online (Sandbox Code Playgroud)
其中实际的val是根据SYSTEM ENVIRONMENT VARIABLE设置的
我正在使用Spring 3.0
public class Sonnet29 implements Poem {
private String[] poem;
public Sonnet29() {
poem = { "foo", "bar" , "baz"};
}
@Override
public void recite() {
//...
}
}
Run Code Online (Sandbox Code Playgroud)
行poem = { "foo", "bar" , "baz"};正在给出编译错误.
有什么理由不允许这样做?如何使用数组常量初始化String数组?
编辑:谢谢大家的答案.现在我清楚什么是允许的,什么不是.但我可以问你为什么不允许这样做?
String[] pets;
pets = {"cat", "dog"};
Run Code Online (Sandbox Code Playgroud)
谷歌搜索后,我发现这个链接,其中,它被告知这样的编码使编译器不明确 - 宠物应该是字符串数组还是对象数组.但是从声明中,它可以很好地弄清楚它是一个String数组,对吗?
以下是我的帮助类获取数据库连接:
我已经使用了这里描述的C3P0连接池.
public class DBConnection {
private static DataSource dataSource;
private static final String DRIVER_NAME;
private static final String URL;
private static final String UNAME;
private static final String PWD;
static {
final ResourceBundle config = ResourceBundle
.getBundle("props.database");
DRIVER_NAME = config.getString("driverName");
URL = config.getString("url");
UNAME = config.getString("uname");
PWD = config.getString("pwd");
dataSource = setupDataSource();
}
public static Connection getOracleConnection() throws SQLException {
return dataSource.getConnection();
}
private static DataSource setupDataSource() {
ComboPooledDataSource cpds = new ComboPooledDataSource();
try {
cpds.setDriverClass(DRIVER_NAME);
} …Run Code Online (Sandbox Code Playgroud) 最近我遇到了一个问题:如何避免实例化Java类?
但是,我回答说:
如果您不想实例化类,请使用"abstract"修饰符.例如:javax.servlet.HttpServlet被声明为抽象(尽管它的方法都不是抽象的)以避免实例化.
声明一个无参数的私有构造函数.
现在我的问题是a)还有其他方法吗?b)为什么任何人都不想实例化一个类?-在SO搜索后,我从知道这个那个的Util类可以做出不实例化.我们不想在OOP中实例化一个类的任何其他地方?
作为核心开发人员几年,编写应用程序看到类图,序列图,我决定改善自我,采取下一步设计.由于我是OO开发人员,我有兴趣提高我的设计技能.
例如,我很难设计货币转换器.
我对SO的问题:
总之,给定一个问题,我只想以面向对象的方式解决它?
public class Category {
private Category parentCategory;
private Set<Category> childCategories;
private String name;
public Category() {
childCategories = new HashSet<Category>();
}
public Category getParentCategory() {
return parentCategory;
}
public void setParentCategory(Category parentCategory) {
this.parentCategory = parentCategory;
}
public Set<Category> getChildCategories() {
return childCategories;
}
public void setChildCategories(Set<Category> childCategories) {
this.childCategories = childCategories;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Category [childCategories=" + childCategories + …Run Code Online (Sandbox Code Playgroud)