[Solved] In the main class to make an array of Contact [closed]

public static void main (String … args) { ArrayList<Contanct> contacts = new ArrayList<Contact>(); Contact c1= new Contact(); c1.setName(“John”); c1.setAddress(“Arthur Street 10”); c1.setTelephone(“123”); Contact c2= new Contact(); c2.setName(“Peter”); c2.setAddress(“Sam Street 2”); c2.setTelephone(“456”); contacts.add(c1); contacts.add(c2); String result= “”; //Put it to a String for (Contact c : contacts) { result+=c.toString() + “$”; } result = result.substring(0, result.length() … Read more

[Solved] Java splitting map from a nested map [closed]

The question is unclear so I’ll try to answer, but listing my assumptions. If my assumptions are incorrect, then ofcourse the answer is going to be incorrect. I am assuming that the {domains={A={ notation does not mean you have this as text but that you have a map containing a map, containing a map. I … Read more

[Solved] Why is Android System.currentTimeMillis() not an accurate Timestamp? [duplicate]

While epoch time is measured in seconds, System.currentTimeMillis() returns the time in milliseconds for more accuracy, which is the value you see in the example. If you divide it by 1000 you will get the time in seconds, which will convert to the current epoch time you expect. You can paste the value in here … Read more

[Solved] Switch case Java error in coding [closed]

char eng = jTextField1.getText().charAt(0); //if you method return a String it gets the 1st character switch(eng){ case’a’: case’e’: case’i’: case’o’: case’u’: jTextField2.setText(“It is a vowel”); break; default: jTextField2.setText(“It is not a vowel”); break; } But better way : char eng=jTextField1.getText().charAt(0); ArrayList<Character> list=new ArrayList<Character>(); list.add(‘a’); list.add(‘e’); list.add(‘i’); list.add(‘o’); list.add(‘u’); list.add(‘y’); if(list.contains(eng)){ jTextField2.setText(“It is a vowel”); }else{ … Read more

[Solved] I am attempting write a class that multiplies two matrices using arrays. Are there any errors in the code? [closed]

int Frows = FM.length; int Fcolumns = FM[0].length; int Srows = FM[0].length; int Scolumns = FM.length; should be int Frows = FM.length; int Fcolumns = FM[0].length; int Srows = FM.length; int Scolumns = FM[0].length; and … float finAns[][] = new float[Fcolumns][Scolumns]; should be float finAns[][] = new float[Frows][Scolumns]; Start with that solved I am attempting … Read more

[Solved] How to format my date to Default format [closed]

Use LocalDateTime with its toString(). String s = LocalDateTime.now().toString(); // ISO standard representation // LocalDateTime to old Date: Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); // Old Date holding time to LocalDateTime: LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); Of cause with an SQL PreparedStatement, you could simply call setDate without the detour via String. solved How to format my … Read more

[Solved] What is the encoding of Java byte type?

Bytes don’t have an encoding. They’re bytes. See the Javadoc of String.getBytes(): Encodes this String into a sequence of bytes using the platform’s default charset So, it’s whatever your default charset is. You can find out what that is at runtime using Charset.defaultCharset(). If you want the bytes in a particular charset, specify it, e.g.: … Read more

[Solved] Why ArrayIndexOutOfBound Exception can be caught in Java, but C++ program crashes instead? [duplicate]

Since you were asked this question in an interview, the interviewer was probably trying to gain some knowledge about your understanding of principles behind C++ design. In this case, the principle the interviewer was looking to discuss is that in C++ you don’t pay for things that you do not explicitly request. Although bounds checking … Read more

[Solved] I have an interface’s method that can’t be called [duplicate]

The problem is that the compiler tells me that he “cannot resolve the method beStored(int). That simply means that you’re attempting to pass an int type to the beStored method. If you look at the interface definition of this method again you’ll notice that you’re not obeying the contract that has been set. public void … Read more

[Solved] What is best option for dealing with date types in Android?

Support for Java 8 language features requires a new compiler called Jack. Jack is supported only on Android Studio 2.1 and higher. So if you want to use Java 8 language features, you need to use Android Studio 2.1 to build your app. Source: developer.android.com/guide/platform/j8-jack.html For date’s and Timestamp you can see the links given … Read more

[Solved] How to split strings based on “/n” in Java [closed]

Don’t split, search your String for key value pairs: \$(?<key>[^=]++)=\{(?<value>[^}]++)\} For example: final Pattern pattern = Pattern.compile(“\\$(?<key>[^=]++)=\\{(?<value>[^}]++)\\}”); final String input = “$key1={331015EA261D38A7}\n$key2={9145A98BA37617DE}\n$key3={EF745F23AA67243D}”; final Matcher matcher = pattern.matcher(input); final Map<String, String> parse = new HashMap<>(); while (matcher.find()) { parse.put(matcher.group(“key”), matcher.group(“value”)); } //print values parse.forEach((k, v) -> System.out.printf(“Key ‘%s’ has value ‘%s’%n”, k, v)); Output: Key ‘key1’ … Read more

[Solved] How can I use Program a game after swing.Timer stopped?

Your problem is that you don’t use correct architecture pattern. You should separate your business logic from your presentation. Also you should store variables (like time_left) in model, not in the controller (i.e. ActionListener). Please read about: Model View Controller pattern. It’s a basic pattern and it’ll solve most of yours problems. Basic Example Editor.java … Read more