[Solved] Needing help understanding piece of Java code

On your class DVDPlayer you chose to say that a regular DVDPlayer cannot record. So you set it to false. If you want it to record you either change the variable directly, like you did on the class DVDPlayerTestDrive. The boolean canRecord = false is only meant to show you that it is possible to … Read more

[Solved] How to retrieve an element inside a Map in Java?

Your ENUM values on the map seem like another map. Therefore I put it like this Map<Enum, Map<String, Object>> However, question is not clear! Here is one possible solution. import java.util.*; public class Main { public static void main(String[] args) { Map<Enum, Map<String, Object>> map = new HashMap<>(); Map<String, Object> value = new HashMap<>(); value.put(“String1”, … Read more

[Solved] Character Comparison [closed]

if you don’t want to/can’t use libraries c==’ ‘||c==’\t’||c==’\n’||c==’\r’ note that \r is a carriage return it’s part of the windows \r\n combination (and used commonly in network protocols) solved Character Comparison [closed]

[Solved] Comparing 2 numbers in a loop not working correctly

To give you an example of a better code: int number1 = scanner.nextInt(); int number2 = 0; while (true) { number2 = scanner.nextInt(); if (number1 == number2){ System.out.println(“Woo!”); break; } number1 = number2; } Explanation: This code will always compare the two last entered numbers. (e.g. 1,2,2 will print Woo!). For better legibility I changed … Read more

[Solved] how do i split the url using split method by checking all the image extension

You can always try to do it like this; var imgUrl = “http://sits/productimages/00670535922278.png?sw=350&sh=350;”; var splitterArray = [‘.jpeg’, ‘.png’, ‘.jpg’, ‘.gif’]; for (var i = 0; i < splitterArray.length; i++) { var imgUrlArray = imgUrl.split(splitterArray[i]); if (imgUrlArray.length > 1) { //Do your thing here } } You use a array of your extensions that will be … Read more

[Solved] How do I start from a specified value in an array?

There is no way to set the initial index of an array: it still has a 1st (index 0) element, it just happens to be null in your case. You can always start iterating from whatever index you want, but you’ll be wasting space. You could always make your own class… class WeirdIndexArray<T> { private … Read more

[Solved] How To Install Eclipse On Linux

1. Install Java. Don’t have Java installed? Search for and install OpenJDK Java 7 or 8 via Software Center. Or install oracle java by following this post. 2. Download Eclipse from its website. Check out your OS Type, 32-bit or 64-bit, by going to ** System Settings -> Details -> Overview,** then select download Linux … Read more

[Solved] Generic Binary Tree Java

Well, there are quite a number of syntax errors: public class Node <T> implements NodeActionInterface { // <T> data; T data; // ^ T is the data type… Node<T> leftTree; Node<T> rightTree; // ^ not really an errror, but you should use the generic here //public <T> Node(<T> data) public Node(T data) // ^ declared … Read more

[Solved] How to open new activity after clicking list view with search bar element?

You can search on a listview and you can use OnItemClickListener From search view new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { mListView.clearTextFilter(); } else { mListView.setFilterText(newText.toString()); //you can use this to filter items } return true; } @Override public boolean onQueryTextSubmit(String query) { return true; } } And in Listview … Read more

[Solved] how to write regex for this expression in java

The short answer: #a.+#((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?) This will match any character except line breaks in the content section, and should match any url. NOTE: You will have to escape all backslashes in the given regex to represent it as a java String literal. Sources for the url regex: What is the best regular expression to check if … Read more

[Solved] Why does this method cause infinite recursion? [closed]

func is always calling itself. There is no stopping condition. Each call creates a new stack frame, until the call stack is full and StackOverflowError is thrown. Recursive methods should always have a stopping condition. For example – n < 0 : public static int func(int n){ int result; if (n >= 0) result = … Read more