Create an array whose index is specified by a list (not necessarily at regular intervals).

I want to create an array f that contains n indexes. The names of these indices are stored in a list of length n, let's call them list.

So I would like something like:

{f[list[[0]]]f[list[[1]], …}

It's about influencing the f[liste[[i]]]to some values.

I tried to create a table, but the problem is that the indexes can not be a list of what I've seen (in the sense that they need to be regularly spaced).

I also tried to use the array function, but I have the same problem. I can not list the indices as a list, it must be a regular distance.

How can I do it?

Java – Get JSON and display it in the list view with forced closing of the array adapter

Java is running and can retrieve JSON, but it can not be displayed in the layout and forcedly closed. I could not figure out what went wrong. I think it's something in the layout, but I'm not sure …

I've added the Java protocol and it shows that Java is running to the end, displaying everything I need on logcat. But it was not displayed in the layout and the app was forcibly closed after that.

public class MainActivity extends AppCompatActivity {

private ListView bookList;
private linear layout linear layout;
private string file = "books.json";

@Override
protected void onCreate (bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
Toolbar toolbar = findViewById (R.id.toolbar);
setSupportActionBar (toolbar);

bookList = findViewById (R.id.bookList);

String jsonStr_books = readAssetsFile (file);
ArrayList books = jsonToArrayList_books (jsonStr_books);
Log.v ("myLog", "arrayList:" + books);

array adapter arrayAdapter = new ArrayAdapter(
this, R.layout.content_main, books);

bookList.setAdapter (arrayAdapter);
displayBookList (books);
Log.v ("myLog", "done");

}

public class book {
public string title;
public string author;

public String toString () {
Return title + "from" + author;
}
}

public String readAssetsFile (String File) {
String json = null;
To attempt {
InputStream is = getAssets (). Open (file);
int size = is.available ();
byte[] buffer = new byte[size];
is.read (buffer);
is near();
json = new string (buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace ();
return zero;
}
return json;
}

public ArrayList jsonToArrayList_books (String jsonStr) {
JSONObject jsonObjTable;

assembly list arrayList = new ArrayList <> ();
To attempt{
jsonObjTable = new JSONObject (jsonStr);
JSONArray jsonArrayTable = jsonObjTable.getJSONArray ("books");

for (int i = 0; i <jsonArrayTable.length (); i ++) {
JSONObject jsonObjRow = jsonArrayTable.getJSONObject (i);
Book book = new book ();

book.title = jsonObjRow.getString ("title");
book.author = jsonObjRow.getString ("author");

arrayList.add (book);

}

} catch (JSONException e) {
Log.v ("myLog", e.toString ());
}
return arrayList;
}

private void displayBookList (ArrayList Arrangement list) {
String bookRow;

for (int i = 0; i "+ bookRow);
}
}


}

Here is the layout:


    

        
    

Here is the JSON:

"Books":[
        {
        "id": "1",
        "title": "test",
        "author": "123"
        },
        {
        "id": "2",
        "title": "A Tale of Two Cities",
        "author": "Charles Dickens"
        },
        {
        "id": "3",
        "title": "Alice in Wonderland",
        "author": "Lewis Carroll"
        }
    ]
}

It should show title + "from" + author in the list view.

array – remove duplicates of the last column in C #

I have a matrix of 3 rows and 4 matrix columns[3,4]:
ABCD
EFGH
DKLM

and I want to eliminate the elements that are the same [i,3] (ie the elements of the last column), if they match any of the elements within the values ​​of [i,j] (j only goes to 2 because I do not take the last column). For example: D is deleted because D is in the last column (matrix)[0,3]) because it repeats itself on the matrix[2,0] and the result passes to a mi_array without the repeated values, the same result: mi_array = {A, B, C, E, F, G, H, K, L, M}

php – How to pass an array to a function in C ++

marked as pending as is not clear enough from Maniero 1 min ago

Clarify your specific problem or add more details to highlight exactly what you need. As it is written here, it is difficult to know exactly what you are asking. For more information about this question, visit the Questions and Answers page. Learn the rules in the help and work on the question accordingly.

java – how to compare two elements in the same array

I want to write the test case with Junit for my ParOfDice class. But i do not know how to compare the elements of the same array. Not two differents array.

public class dice pair {// ParOfDice //

// Create the array
private int[] dice = new int[2];

// Construct of the class
public dice pair () {
    this.roll ();
    this.pasch ();
}


public void roll () {

    // Returns the length before the for loop. This will be faster than we are not
    // Navigate the area again and again.
    int length = wuerfel.length;
    for (int i = 0; i <length; ++ i) {
        cube[i] = (int) ((Math.random () * 6) + 1);
        System.out.println (wuerfel[i]);


    }
}
// If the elements of the array (both dice) are the same
// If we get a message that is the Pasch.
// With this structure, the classes are revocable.

public void pasch () {
    if (dice[0] == dice[1]) {
        System.out.println ( "PASCH");
    }
}

}

Javascript – Find the smallest index that is the same as the value in an array

The task is taken from LeetCode

Given is an array A of different integers sorted in ascending order.
return the smallest index i that satisfies A[i] == i. Returns -1 if no
that's how I exist.

Example 1:

Entrance: [-10,-5,0,3,7]
Edition: 3
Explanation:
// For the specified array, A is[0] = -10, A[1] = -5, A[2] = 0, A[3] = 3, so the output is 3.

Example 2:

Entrance: [0,2,5,8,17]
Output: 0
Explanation:
// ON[0] = 0, so the output is 0.

Example 3:

Entrance: [-10,-5,3,4,7,9]
Output: -1
Explanation:
// There is no such i, that A[i] = i, so the output is -1.

Note:

1 <= A. Length <10 ^ 4

-10 ^ 9 <= A[i] <= 10 ^ 9

My solution

has temporal complexity of $ O (n) $ and space complexity of $ O (1) $, I start to look from the beginning to the last element. If I find a value that is greater than I, then I can leave early (because there is no element that is the same I no more). If I find … ON[i] === ithen I have a result.

Is there a faster solution than the intended one?

/ **
* @param {number[]} ON
* @return {number}
* /
var fixedPoint = function (A) {
for (let i = 0; i < A.length; i++) {
        if (A[i] > i) {return -1; }
when a[i] === i) {return i; }
}
return -1;
};

PHP – WordPress loop of meta-key, which is an array? and how to loop multiple arrays

How can I get a loop of posts for meta values ​​stored in a meta_key that is an array like this?

$ sharedHosting_plans_fields = Array
(
                                        [0] => Array
(
                                                [plan_name] => name 1
                                                [plan_price] => 1
                                                [theType] => yesPaid
                                                [plan_space] => Unlimited
)

                                        [1] => Array
(
                                                [plan_name] => name 2
                                                [plan_price] => 3
                                                [theType] => yesFree
                                                [plan_space] => 5000
)

                                        [2] => Array
(
                                                [plan_name] => name2
                                                [plan_price] => 5
                                                [theType] => yesPaid
                                                [plan_space] => Unlimited
)

)

And I used that

                    & # 39; # 39 & meta_key; => & # 39; sharedHosting_plans_fields & # 39 ;,
& # 39; # 39 & orderby; => & # 39; meta_value_num meta_value & # 39 ;,

but no effect !!!

2-If I want to receive posts by checking several meta keys like this

                Array (
& # 39; key & # 39; => & # 39; plan_type2 & # 39;
)
Array (
& # 39; key & # 39; => & # 39; plan_type3 & # 39;
)
Array (
& # 39; key & # 39; => & # 39; plan_type4 & # 39;
)
Array (
& # 39; key & # 39; => & # 39; plan_type5 & # 39;
)

How can I pass this code for a loop or something else?

I tried to use

                & # 39; # 39 & meta_key; => array (& # 39; sharedHosting_plans_fields & # 39;),
& # 39; # 39 & orderby; => & # 39; meta_value_num meta_value & # 39 ;,

instead of

                & # 39; # 39 & meta_key; => & # 39; sharedHosting_plans_fields & # 39 ;,
& # 39; # 39 & orderby; => & # 39; meta_value_num meta_value & # 39 ;,

but no luck

How do I load a json file array and save it in a field in drupal8?

I receive my Json

//

$ someJSON = & # 39;[{“PhotoFid”:”PhotoFid” : [“8444″,”8445”]}]& # 39 ;;

//

How to transfer this file ID to my field

//

$ node-> set (& # 39; field_photofid & # 39 ;, $ someJSON); – field_photofid is a file type

//

For your information: If it is a single file ID, it will be uploaded automatically, but I'm not sure how to pass this array to my field type