indexof

Search a java.util.List starting at a specific index

十年热恋 提交于 2021-01-27 22:31:25
问题 Is there a built-in method to search a java.util.List specifying the first item to start the search from? Like you can do with Strings I know I can easily implement something on my own, but I'd rather not reinvent the wheel if Java or http://commons.apache.org/collections/api-release/org/apache/commons/collections/package-summary.html already has it. I'm not asking how to implement this, I'm asking whether something is already available A lot of the suggestions here were buggy. If anybody

Getting the object array index in jq

若如初见. 提交于 2021-01-17 07:13:36
问题 I have a json object that looks like this (prodused by i3-msg -t get_workspaces . [ { "name": "1", "urgent": false }, { "name": "2", "urgent": false }, { "name": "something", "urgent": false } ] I am trying to use jq to figure out which index number in the list is based on a select query. jq have something called index() , but it seams to support only strings? Using something like i3-msg -t get_workspaces | jq '.[] | select(.name=="something")' gives me the object I want. But I want it's

Getting the object array index in jq

柔情痞子 提交于 2021-01-17 06:58:05
问题 I have a json object that looks like this (prodused by i3-msg -t get_workspaces . [ { "name": "1", "urgent": false }, { "name": "2", "urgent": false }, { "name": "something", "urgent": false } ] I am trying to use jq to figure out which index number in the list is based on a select query. jq have something called index() , but it seams to support only strings? Using something like i3-msg -t get_workspaces | jq '.[] | select(.name=="something")' gives me the object I want. But I want it's

Finding Index of last character in an input string JAVA?

断了今生、忘了曾经 提交于 2021-01-01 09:58:13
问题 I'm trying to figure out how I can find the index of the last character in the first word in a String variable, while using Scanner class to get the String. In my code I need to use a single String for full name, and find the index of the last character in the first name. So far I made this: String fullName; Scanner s = new Scanner(System.in); System.out.println("Insert full name: "); //For example: Joseph Adams. fullName = s.nextLine(); int position = fullName.indexOf(" "); System.out

Finding Index of last character in an input string JAVA?

落爺英雄遲暮 提交于 2021-01-01 09:57:44
问题 I'm trying to figure out how I can find the index of the last character in the first word in a String variable, while using Scanner class to get the String. In my code I need to use a single String for full name, and find the index of the last character in the first name. So far I made this: String fullName; Scanner s = new Scanner(System.in); System.out.println("Insert full name: "); //For example: Joseph Adams. fullName = s.nextLine(); int position = fullName.indexOf(" "); System.out

How can I correctly check if a string does NOT contain a specific word?

北城以北 提交于 2020-08-19 11:23:36
问题 I am currently trying to figure out how to solve the above named problem. Specifically I want to check if the string does not contain the word "stream" both in capital and lowercase letters. Here's my code so far: if (((gewaesser_name1.includes("Stream") == "false") || (gewaesser_name1.includes("stream") == "false")) && ((gewaesser_name2.includes("Stream") == "false") || (gewaesser_name2.includes("stream") == "false"))) {var a= "..."} The code does obviously not work as the results are not

Index of value in json responsebody (Gatling/Scala)

一笑奈何 提交于 2020-07-10 10:32:06
问题 Given my json response body [{"brukergruppeSperret":false,"virksomhetsnavn":"HELFO","brukerGruppe":"Brukerstøtte"},{"brukergruppeSperret":false,"virksomhetsnavn":"Klubbgaten Legesenter","brukerGruppe":"Lege"},{"brukergruppeSperret":false,"virksomhetsnavn":"Sjøsiden Legesenter","brukerGruppe":"Lege"},{"brukergruppeSperret":false,"virksomhetsnavn":"Athene legekontor Helsedirektoratet","brukerGruppe":"Lege"},{"brukergruppeSperret":false,"virksomhetsnavn":"Xeon Legekontor","brukerGruppe":"Lege"},

indexOf in google script

主宰稳场 提交于 2020-05-30 09:36:04
问题 I'm trying to use findIndex() on a object in google script but it does not work. Here is a exemple: function myFunction() { var searchingJohn = "John"; var DATA = {namesList: []}; DATA.namesList.push({name: "John", otherDataForThisName: []}); var result = DATA.namesList.findIndex(function (element) {return element.name == this;}, searchingJohn); return result; } this work well in a javascript consol but google script return me a "TypeError: Fonction findIndex not found in object....." 回答1:

Returning true if JavaScript array contains an element

北城余情 提交于 2020-05-09 15:59:17
问题 So far I have this code: var isMatch = viewedUserLikedUsersArray.indexOf(logged_in_user); if (isMatch >=0){ console.log('is match'); } else { console.log('no match'); } If an element is in an array it will return a number greater or equal to 0 and so I can say isMatch >=0 but this doesn't seem the safest way. How else can I return a true/false from the desired code? 回答1: You could just use Array.prototype.some var isMatch = viewedUserLikedUsersArray.some(function(user){ return user === logged

How can I find all the elements in javaScript array that start with certain letter

送分小仙女□ 提交于 2020-03-16 06:55:11
问题 Is there any way to do this filtering out only items in an array that start with the letter a. ie var fruit = 'apple, orange, apricot'.split(','); fruit = $.grep(fruit, function(item, index) { return item.indexOf('^a'); }); alert(fruit); 回答1: Three things: You want to split by ', ' , not ',' indexOf doesn't take a regex, but a string, so your code searches for a literal ^ . Use search if you want to use regular expressions. indexOf (and search ) do return the index where they find the sought