[Solved] How to calculate percentage of matching values on two arraylists?

Try this: List<String> actual = new ArrayList<>(); List<String> required = new ArrayList<>(); List<String> common = new ArrayList<>(actual); common.retainAll(required); System.out.println(” 100.0 * common / actual = ” + (actual.size() == 0 ? 0 : 100.0 * common.size() / actual.size())); System.out.println(” 100.0 * common / required = ” + (required.size() == 0 ? 0 : 100.0 * … Read more

[Solved] Reshaping a weird list in python [duplicate]

IIUC, given array = [[[0,0,1,0],[0,0,0,1],[1,0,0,0],[0,1,0,0]], [[0,1,0],[1,0,0],[0,0,1],[0,0,1]], [[0],[1],[0],[1]], [[1],[1],[0],[1]]] Do import numpy as np >>> np.array(array).T array([[list([0, 0, 1, 0]), list([0, 1, 0]), list([0]), list([1])], [list([0, 0, 0, 1]), list([1, 0, 0]), list([1]), list([1])], [list([1, 0, 0, 0]), list([0, 0, 1]), list([0]), list([0])], [list([0, 1, 0, 0]), list([0, 0, 1]), list([1]), list([1])]], 2 solved Reshaping a … Read more

[Solved] how to add object in nested array of objects without mutating original source

Use Array.prototype.map instead, forEach gets no returns let newobj = [ { id: 22, reason: ‘reason 2’, phase: ‘phase 2’, reviewer: ‘by user 2’, date: ‘date 2’ }, { id: 21, reason: ‘reason 1’, phase: ‘phase 1’, reviewer: ‘by user 1’, date: ‘date 1’ } ]; let arr1 = { initiateLevel: true, parent: [ { … Read more

[Solved] Trouble copying the string using memcpy

The command strcat(a[0],”\0″); is working on strings which are already terminated by \0. Otherwise it doesn’t know where to append the second string. In your case a[0] is not terminated, so the function will induce undefined behavior. You can do the following instead: a[0][n] = ‘\0’; (the same is for the rest of a elements) … Read more

[Solved] Array copies zeros? [closed]

In the loop below value is stored in fixarray only when element in array1 is not zero but its index gets incrementated even when element is zero. for (i = 0; i < linect; i++) { if (array1[i] > 0.5) { fixarray1[i] = array1[i]; fixarray2[i] = array2[i]; } } In this loop index of fixarray … Read more

[Solved] enhanced for loop (java) [duplicate]

You can do it using syntax like the following: for (String s: cdSporNavn){ if(s.indexOf(“java”) != -1){ System.out.println(s); } } See Using Enhanced For-Loops with Your Classes for further information and examples. 0 solved enhanced for loop (java) [duplicate]

[Solved] How to split string into an array? [closed]

Split the string into array: String x = “What is my name”; String[] splitted = x.split(” “); for (int i = 0; i < Array.getLength(splitted); i++) { System.out.println(“Word ” + (i+1) + “: ” + splitted[i]); } You can change System.out.println() to your desired output method. Edit (as suggested in comment): For safer code, change … Read more