[Solved] calculate the length of line using toString

The toString() method of the Point class should look like: public String toString() { return “(” + x + “,” + y + “)”; } The toString() method of the Line class should look like (supposing you have two members of type Point in the class Line): public String toString() { return “(” + point_A.getX() … Read more

[Solved] I want to print only the repeated values once from an associative array

Use filter and map, with a Set to remove the repeated values: var employee=[{“firstName”:”Zahir”,”lastName”:”Alam”,”Age”:25,”Company”:”Switchme”,”Role”:”Developer”,”Department”:”Tech”,”Head”:{“Id”:3,”Name”:”Sourasis Roy”}},{“firstName”:”Amith”,”lastName”:”Manniken”,”Age”:25,”Company”:”Switchme”,”Role”:”Developer”,”Department”:”Tech”,”Head”:{“Id”:3,”Name”:”Sourasis Roy”}},{“firstName”:”Sourasis”,”lastName”:”Roy”,”Age”:28,”Company”:”Switchme”,”Role”:”CTO”},{“firstName”:”Aditya”,”lastName”:”Mishra”,”Age”:29,”Company”:”Switchme”,”Department”:”Tech”,”Role”:”CEO”},{“firstName”:”Priti”,”lastName”:”Lata”,”Age”:24,”Company”:”Switchme”,”Role”:”HR”},{“firstName”:”Sumita”,”lastName”:”Nath”,”Age”:24,”Company”:”Switchme”,”Role”:”HLA Head”,”Department”:”Crm”},{“firstName”:”Tarini”,”lastName”:”Khanna”,”Age”:22,”Company”:”Switchme”,”Role”:”Content Writer”},{“firstName”:”Abhisek”,”lastName”:”Soni”,”Age”:23,”Company”:”Switchme”,”Role”:”HLA”,”Department”:”Crm”,”Head”:{“Id”:5,”Name”:”Sumita Nath”}},{“firstName”:”Ankit”,”lastName”:”Pump”,”Age”:23,”Company”:”Switchme”,”Role”:”HLA”,”Department”:”Crm”,”Head”:{“Id”:5,”Name”:”Sumita Nath”}},{“firstName”:”Pogo”,”lastName”:”Laal”,”Age”:23,”Company”:”Switchme”,”Role”:”Designer”},{“firstName”:”Sabina”,”lastName”:”Sekh”,”Age”:28,”Company”:”Switchme”,”Role”:”HLA Head”,”Department”:”Crm”},{“firstName”:”Sanjay”,”lastName”:”Poudal”,”Age”:24,”Company”:”Switchme”,”Role”:”HLA Head”,”Department”:”Crm”,”Head”:{“Id”:10,”Name”:”Sabina Sekh”}}]; var repeated = […new Set(employee.map(({ Department }) => Department).filter(Boolean))]; $(“div.all”).text(repeated.join(“, “)); <script src=”https://code.jquery.com/jquery-3.3.1.js”></script> <h3>2. List out all department name </h3> <div class=”all”></div> 7 solved I want to print only the repeated values … Read more

[Solved] Javascript object sorting [closed]

You can’t sort properties in an object. Copy the data into an array and sort it. Example: var arr = []; $.each(data, function(key, value){ arr.push({ id: key, data: value }); }); arr.sort(function(x,y){ var xn = x.data.userStatuINT; var yn = y.data.userStatuINT; return xn == yn ? 0 : xn < yn ? -1 : 1; }); … Read more

[Solved] Android : How To convert Object to String

Modifying answer now that I understand you want the resource identifier of your views: Resources res = getResources(); for (int i = 0; i < ListOfView.size(); i++){ int id = ListOfView.get(i).getId(); try { Log.i(“View “, res.getResourceName(id)); } catch (Resources.NotFoundException e) { Log.i(“Unknown id ” + id); } } 5 solved Android : How To convert … Read more

[Solved] Javascript object in array

You can proceed like this: var products = {a:”b”, c:”d”, e:”f”}; var arrList = []; for(var key in products) { // iterates over products key (e.g: a,c,e) arrList.push([key, products[key]]); }; solved Javascript object in array

[Solved] How to modify an array of objects containing values of the same name?

Something like this might work for you: var i; var k; for(i = 0; i < existingArray.length; i++){ var count = 2; for(k = 0; k < existingArray.length; k ++){ if(i != k && existingArray[i].content.host.name === existingArray[k].content.host.name){ existingArray[k].content.host.name += ‘_’ + count; count++; } } } 3 solved How to modify an array of objects … Read more

[Solved] How to insert an array into a nested JavaScript Object

We can use map, filter reduce for this, it’s slightly tricky but the same principle applies: const data = { periods: [ { decisions: [ { bank: { name: “Team1” }, bSPositionDecisions: [ { totalInputRate: 1.0, positionValue: 12, balanceSheetPosition: { name: “asset_bc_lombard_a_onsight”, category: “LOMBARD_LOANS”, type: “ASSET” } }, { totalInputRate: 2.0, positionValue: 10, balanceSheetPosition: { … Read more

[Solved] Android java type org.json.JSONObject cannot be converted to JSONArray

Change JSONArray list = new JSONArray(Jo_result.getString(“result”)); To JSONObject list = new JSONObject(Jo_result.getString(“result”)); Your string is contained between {} which makes it an object. Keep in mind this {} = Json Object [] = Json Array UPDATE When you do this JSONObject resultsObject = list.getJSONObject(i); it’s expecting another object within the main object, for example : … Read more

[Solved] how to use function correctly in java

thanks to all…..the thing which i dont know was – during a function call if i want to pass an array(arr[]) as argument then i just need to pass its name(arr) as argument not the square brackets([]) along with it. Here is my new optimized error free code which has been submitted successfully. import java.util.*; … Read more