我想转换Tue Jun 01 00:00:00 IST 112成01-JUN-2012
我用了
Calendar calendar = new GregorianCalendar(year, 6, Calendar.DAY_OF_MONTH);
Date maxDate=new Date();
maxDate=calendar.getTime();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
SimpleDateFormat s=new SimpleDateFormat("dd-mmm-yyyy");
s.format(maxDate);
Run Code Online (Sandbox Code Playgroud)
但我明白了 30-000-0112
class A{
@Override
public int hashCode() {
return 10;
}
}
public class SampleClass {
public static void main(String[] args){
Map map = new HashMap();
map.put(new A(), "A");
map.put(new A(), "B");
System.out.println(map.size());
System.out.println(new A().hashCode());
System.out.println(new A().hashCode());
}
}
Run Code Online (Sandbox Code Playgroud)
输出: -
2
10
10
Run Code Online (Sandbox Code Playgroud)
为什么2 ??? 如果我们正在实现返回相同整数的hashCode方法.不应该大小为1 ???
SimpleDateFormat formatter = new SimpleDateFormat("mm/dd/yyyy");
dt = formatter.parse(temp[0]);
Run Code Online (Sandbox Code Playgroud)
给了我错误
java.text.ParseException:无法解析的日期:"30-MAR-07"
有没有什么办法可以将给定的String格式化为Date对象,而无需编写自己的字符串拆分和转换为月份数字方法?谢谢
我有问题重定向到jsp.我把我的servlet代码放在下面.而且我也把错误日志.任何人都可以帮我解决问题.如果您需要进一步的细节,请在下面评论.我在其他servlet中做了同样的工作.
public class DoctorServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sDocId=request.getParameter("doctorId");
Integer dId=Integer.parseInt(sDocId);
String speciality=request.getParameter("speciality");
String experience=request.getParameter("experience");
String qualification=request.getParameter("qualification");
String sempId=request.getParameter("employeeId");
Integer empId=Integer.parseInt(sempId);
String action=request.getParameter("method");
Doctors d=new Doctors();
if(action.equalsIgnoreCase("add")){
d.setDocId(dId);
d.setEmpId(empId);
d.setExp(experience);
d.setSumOfQn(qualification);
d.setSpeciality(speciality);
try {
boolean result=new Doctors().insertDoctor(d);
if(result==true){
request.setAttribute("add","sucess");
}
request.getRequestDispatcher("doctor_result.jsp").forward(request, response);
response.sendRedirect("doctor_result.jsp");
} catch (SQLException ex) {
Logger.getLogger(DoctorServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Aug 23, 2012 12:29:50 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [DoctorServlet] in context …Run Code Online (Sandbox Code Playgroud) 编写名为Nameable的接口,指定以下方法:
public void setName(String n)
public String getName()
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
public interface Nameable{
public void setName(String n){
n =name; }
public String getName() {
return n; } }
Run Code Online (Sandbox Code Playgroud)
这是正确的还是有更好的方法吗?
所以,我找到了java.util.Calendar,并尝试将它用于我正在研究的android项目.
我完全不明白Calendar.DAY_OF_WEEK如何在星期四返回7?现在当它是八月Calendar.WEEK_OF_YEAR返回4,这根本没有任何意义!
我也尝试了GregorianCalendar,它给出了完全相同的结果.
试图找到有关它们如何计算的任何文档,但我找不到任何东西.似乎有一些非常明显的东西,但我无法找出它是什么!
我写的代码在这里:
// Get if daily or weekly
boolean daily;
daily = getPrefs.getBoolean("checkbox_daily", false);
String day = "0";
if (daily){
switch(GregorianCalendar.DAY_OF_WEEK){
case GregorianCalendar.MONDAY:
Do_stuff();
break;
case GregorianCalendar.TUESDAY:
Do_stuff();
break;
case GregorianCalendar.WEDNESDAY:
Do_stuff();
break;
case GregorianCalendar.THURSDAY:
Do_stuff();
break;
case GregorianCalendar.FRIDAY:
Do_stuff();
break;
}
}
Run Code Online (Sandbox Code Playgroud) 我是Java新手,我正在使用eclipse进行编译.我见过很多论坛,但我无法解决这个错误.我正在为我的作业创建一个程序,这是该程序的一小部分,它给出了奇怪的错误.任何帮助表示赞赏.
这是我得到错误的地方 - > aTwoD[i][j] = 0; <- at Initialize2D.<init>(Initialize2D.java:19)
我现在已经坚持了很长一段时间.:-(
做了什么 - >
public class Initialize2D
{
private int[][] aTwoD;
public Initialize2D (int N)
{
System.out.println("N = " +N);
int counter = 0;
aTwoD = new int[N][N];
int i = 1;
while( i <= N )
{
int j = 1;
while( j <= N )
{
System.out.println("counter = " +counter);
aTwoD[i][j] = 0;
System.out.println("aTwoD["+i+"]["+j+"] = " + aTwoD[i][j]);
j++;
counter++;
}
i++;
}
}
public static void main( …Run Code Online (Sandbox Code Playgroud) import java.util.*;
class U {
int x;
U(int x) {
this.x = x;
}
}
public class G {
public U a = new U(22);
public U b = new U(23);
Integer y = 22;
Integer r = 23;
void a() {
Map<U, Integer> set = new HashMap<U, Integer>();
set.put(a, y);
set.put(a, r);
set.put(b, y);
System.out.print(set.size() + " ");
}
public static void main(String[] args) {
G m = new G();
m.a();
}
}
Run Code Online (Sandbox Code Playgroud)
我总是对地图和列表感到困惑.我知道当map将密钥放入集合时,它会调用hashcode,如果存储桶相同,则调用equal方法.但是,我了解到,如果类重写这两个方法,则不会存储重复的键.例如包装类:String实现自己的hashcode和equal方法.此外,如果您不这样做,则会调用唯一的哈希码,并且重复的密钥将存储在集合中.
但是在上面的例子中,类U没有实现hashcode和equal方法.但是,Map不允许重复键.
我检查了SIZE:它的2应该是3,因为我的U类没有实现hashcode也没有.
请清除我
提前致谢
我正在玩java 1.8.我读到新的集合api工作得更快,因为它在并行化的数据结构上运行操作.
我想看看这个efford.所以我写了下面的代码:
public static void main(String[] args) {
ArrayList<SamplePerson> persons = new ArrayList<>();
for (long i = 0; i < 10000000; i++) {
persons.add(new SamplePerson(EyeColour.BLUE,20,"Max Musterman",Gender.MALE));
}
long nsBefore = System.nanoTime();
// using the new collection api - parallel way??
persons.forEach(samplePerson -> samplePerson.setAge(22));
// sequential way
for(int i = 0; i < persons.size(); i++){
persons.get(i).setAge(22);
}
long nsAfter = System.nanoTime();
long runtime = nsAfter - nsBefore;
System.out.println("Time in Nanoseconds: " + runtime);
}
Run Code Online (Sandbox Code Playgroud)
我的处理器:i7-2600 CPU
使用"并行"方式的结果:以纳秒为单位的时间:74836825
使用顺序方式的结果:以纳秒为单位的时间:45071315
大家可以解释一下这个结果吗?建立这种威胁的开销是否很高?我有点困惑请帮帮我:-)
我正在使用 Maven 构建一个项目,并使用 Jenkins 进行持续集成。在 Maven 构建之后,我在目标文件夹中获得了一个可执行 jar,我尝试使用 Windows 批处理命令作为构建步骤来运行它。但是当我将命令放入“执行 Windows 批处理命令”下的框中时,出现以下错误
“cmd /c call /tmp/hudson2033384960131825453.bat 致命:命令执行失败 java.io.IOException:无法运行程序“cmd”(在目录“/hosting/workspace/myProject”中):错误=2,没有这样的文件或目录””
我使用的是 Mac OSX 10.9.3。詹金斯部署在我无权访问的远程服务器中。
我想将这个 jar 文件作为构建过程来执行。我该怎么做?