[Solved] How to get month and day from the timestamp in java [duplicate]

String ts = “2019-01-21T05:56:46.000Z”; String date = ts.split(“T”)[0]; String[] splitDate = date.split(“-“); int day = Integer.parseInt(splitDate[2]); String month = “”; switch(Integer.parseInt(splitDate[1])) { case 1: month = “JAN”; break; case 2: month = “FEB”; break; . . . } System.out.println(“Day: ” + day + “, Month: ” + month); 1 solved How to get month and … Read more

[Solved] How Java ArrayList works internally [closed]

If you pass an ArrayList to a function it passes a pointer back to the original list. That means any updates in the method will be updating your original ArrayList because they are the same thing. ArrayList<String> list2 = new ArrayList<String>(list); That makes a copy of list and saves it into list2. list and list2 … Read more

[Solved] How to stop substraction if that is not possible? [closed]

You’re already using an if statement. That’s the key to what you want. int a = Integer.parseInt(cijenaIgraca.getText()); int b = Integer.parseInt(kapital.getText()); if(b < a) { this.porukica.setText(“Usli ste u minus, imacete troskove!”); } else { String c = String.valueOf(b-a); this.kapital.setText(c); } Just add an else part as shown so the subtraction will only happen in that … Read more

[Solved] Equivalent java code for this kotlin code? [closed]

Sorry this might be slightly off, but it’s the best that I can do with the amount of code that’s provided in Java 8 (and without actually reading through the provided Github repo): private void showNoMoreCards() { showContent((layoutBuilder) -> { layoutBuilder.row((rowBuilder) -> { rowBuilder.label(LEFT_MARGIN, “Congratulations, you’ve reviewed all the cards for now!”); }); }); } … Read more

[Solved] Sequences in JAVA [closed]

This works for me. public static void main(final String[] args) { final String input = “aaaab aOa baaab c”; final String[] sections = input.split(” “); final int length = 3; final List<String> list = new ArrayList<>(); for (final String section : sections) { for (int i = 0; i < section.length(); i++) { if (section.length() … Read more

[Solved] How to get the JSON error response and toast it?

Just change this code: jObject = new JSONObject(result); if (jObject.has(“error”)) { String aJsonString = jObject.getString(“error”); Toast.makeText(getBaseContext(), aJsonString, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getBaseContext(), “Login Successful”, Toast.LENGTH_SHORT).show(); } } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); Toast.makeText(getBaseContext(),result+”” , Toast.LENGTH_SHORT).show(); } So by this code, if your response is not JSON it will throw exception … Read more

[Solved] Why cannot I return values from two functions in Java?

Closing the Scanner also closes the input stream it’s scanning — in this case System.in. Hence, when you subsequently call getYear(), it finds the input stream System.in already closed. One way to avoid this is to use the same Scanner in both methods, by passing it as an argument to the methods. From the Java … Read more

[Solved] Error in android code [closed]

You can find the number of common characters by the following method. I have changed p to int bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ArrayList<Character> charArray1 = new ArrayList<Character>(); ArrayList<Character> charArray2 = new ArrayList<Character>(); for (char character : st1.toString().toCharArray()) { charArray1.add(character); } for (char character : st2.toString().toCharArray()) { charArray2.add(character); } for (Character … Read more

[Solved] about if and while statement in java programming? [closed]

You can have an if statement in a while statement, etc, and instead of doing else, you can do: if(!bool) return “bool isn’t true”; Instead of doing if(bool){}else{return “bool isn’t true”;} Replace bool with whatever value you want to compare. You may replace bool with things like x>y(if x is greater than y) or a … Read more