arrays

Printing all elements of an array in one println statement in Java [duplicate]

孤街醉人 提交于 2021-02-16 23:56:37
问题 This question already has answers here : What's the simplest way to print a Java array? (32 answers) Closed last month . public class Test { public static void main(String[] args) { int[] a= new int[]{1,2,3}; System.out.println(a); } } I expected to take a compile or run-time error.I took an output.It's " [I@1ba4806 ".What's the reason of it in Java? 回答1: That's the default implementation of toString() in Object you're seeing. You can use Arrays.toString for a readable result (make sure to

How to groupBy array of objects based on properties in vanilla javascript

一世执手 提交于 2021-02-16 22:51:48
问题 How do you groupBy array of objects based on specific properties in vanilla javascript? For example this given: const products = [ { category: "Sporting Goods", price: "$49.99", stocked: true, name: "Football" }, { category: "Sporting Goods", price: "$9.99", stocked: true, name: "Baseball" }, { category: "Sporting Goods", price: "$29.99", stocked: false, name: "Basketball" }, { category: "Electronics", price: "$99.99", stocked: true, name: "iPod Touch" }, { category: "Electronics", price: "

How to groupBy array of objects based on properties in vanilla javascript

随声附和 提交于 2021-02-16 22:49:52
问题 How do you groupBy array of objects based on specific properties in vanilla javascript? For example this given: const products = [ { category: "Sporting Goods", price: "$49.99", stocked: true, name: "Football" }, { category: "Sporting Goods", price: "$9.99", stocked: true, name: "Baseball" }, { category: "Sporting Goods", price: "$29.99", stocked: false, name: "Basketball" }, { category: "Electronics", price: "$99.99", stocked: true, name: "iPod Touch" }, { category: "Electronics", price: "

How I can access array elements of List

旧城冷巷雨未停 提交于 2021-02-16 22:46:51
问题 I have a question: I have a List Java that I have populated with different values. For example, I have: List<String[]> l = new ArrayList(); String[] lis = new String[3]; lis[0] = "A"; lis[1] = "B"; lis[2] = "C"; l.add(lis); and I have other values too. Now, I want to get the search in this list only the first field. For example, I want the A's indexOf. I have tried to write this code: int index = l.indexOf("A"); but I get -1 as return. I would like to know how I can access to a field of the

How I can access array elements of List

懵懂的女人 提交于 2021-02-16 22:45:30
问题 I have a question: I have a List Java that I have populated with different values. For example, I have: List<String[]> l = new ArrayList(); String[] lis = new String[3]; lis[0] = "A"; lis[1] = "B"; lis[2] = "C"; l.add(lis); and I have other values too. Now, I want to get the search in this list only the first field. For example, I want the A's indexOf. I have tried to write this code: int index = l.indexOf("A"); but I get -1 as return. I would like to know how I can access to a field of the

How I can access array elements of List

浪尽此生 提交于 2021-02-16 22:45:20
问题 I have a question: I have a List Java that I have populated with different values. For example, I have: List<String[]> l = new ArrayList(); String[] lis = new String[3]; lis[0] = "A"; lis[1] = "B"; lis[2] = "C"; l.add(lis); and I have other values too. Now, I want to get the search in this list only the first field. For example, I want the A's indexOf. I have tried to write this code: int index = l.indexOf("A"); but I get -1 as return. I would like to know how I can access to a field of the

How to sort this multidimensional array by points?

ⅰ亾dé卋堺 提交于 2021-02-16 21:23:48
问题 I have a script that runs through football fixtures, each day it will work out the teams played, wins, draws, losses, gd and points. At the end of each day it will upload the table to the database, so that I have a different table for each day (I have my reasons for it lol) Problem is here is an example my code that creates the array. if (array_key_exists(strval($firstDate), $matches)) { // Matches Exist foreach($matches[$firstDate] as $matchList) { $homeName = $matchList['homeTeamName'];

Python-like array filling - C equivalent

别来无恙 提交于 2021-02-16 21:08:45
问题 I would like to know what would be the equivalent for filling an array like we do in Python, but in C. Python example code: arrayname=[0]*10 randomtextvar="test_text" for i in range(10): arrayname[i]=randomtextvar for k in range(10): print(arrayname[k]+" "+str(k)+ " position") I haven't find an solution for this, I don't really understand how to set value to a string (char) array position (in C) . EDIT: #include <stdio.h> #include <string.h> int main() { int c = 0; char arr[256]; fgets(arr,

Split string into array using multi-character delimiter

自作多情 提交于 2021-02-16 20:26:11
问题 I need to split a string into an array. My problem is that the delimiter is a 3 character one: _-_ For example: db2-111_-_oracle12cR1RAC_-_mariadb101 I'd need to create the following array: db2-111 oracle12cR1RAC mariadb101 Similar questions followed this approach: str="db2-111_-_oracle12cR1RAC_-_mariadb101" arr=(${str//_-_/ }) echo ${arr[@]} Even if the array is created, it has been split uncorrectly: db2 111 oracle12cR1RAC mariadb101 It seems that the "-" character in the first item causes

Joi Validation Regex or pattern

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-16 20:23:49
问题 I want to joi use regex pattern which define in variable I have a variable pattern which contains regex i.e pattern = "/^[0-9+]{7}-[0-9+]{1}$/" and this pattern send to Joi module and want to confirm module.exports = { save: { body: { match: Joi.string().regex(pattern).required } } } I know validation work if I use this module.exports = { save: { body: { match: Joi.string().regex(/^[0-9+]{7}-[0-9+]{1}$/).required } } } But in my case every time regex will different. So I can not use above