Skip to content
Advertisement

Tag: arrays

how to print a single output in for loop?

How can I print only one output in for loop? If the number is in array then it will print “Present” but if the number is not in the array it will print “Nope”. And I need to search the number the user inputed. Input: output: Expected Output: Present Answer You need to maintain a variable outside the loop and

MessageDigestMessage Digest returning different key after first digest

Here is how I initialize MessageDigest And here is how digest to get bytes for password which I later convert to string (no issue there) Now assume the password is “Password@1”. Here is the output first time (apologies for long text below) 115,83,48,-2,41,29,-99,71,-54,-53,-26,-67,-118,48,-75,77,13,100,42,70,-72,110,-85,23,-38,119,-110,-15,121,3,-25,114,-68,109,-108,94,-122,65,-62,10,-90,8,-125,114,-118,51,-51,89,127,55,37,83,-126,56,-31,-27,-49,-60,25,74,-80,-110,23,45 And here is output second time onwards. It remains same after this. -62,-50,45,-44,91,-86,16,90,85,53,101,-122,51,12,-82,52,-123,-101,-10,-28,-108,114,120,-96,84,-23,38,-75,78,67,36,-93,-88,-11,79,76,126,-34,-2,109,76,-31,-30,-86,-28,13,-91,-22,-65,-128,108,-47,15,19,95,60,-30,-123,-4,20,-64,21,-1,7 Can some one please

Find passwords values in JSON objects using Regex

I have a big JSON object which contains a lot of different JSON, most of them have the structure below (key: sometext-v1.password, and value: password for example: I want to use Regex to extract all passwords by a name which contains ‘password’ string and its value, but I don’t want to iterate the JSON name by name because this takes

Casting Issue for Generic Array of Node Objects

I am having problem with java generic array creation where I needed to make an array of type Node. So, I did this for declaration: private Node<E> [] nodes; and later for initialization, nodes = (Node<E>[]) new Node [values.length]; When I try to do something like set the Node object’s attribute value nodes[i].setValue(values[i]); , I get NullPointerException, meaning that there

Remove a specific row from a 2D Array

Given a 2D array and a string, how can I remove a row which does not contain a specific string? So far, I created a nested for loop which iterates through the array, adding all adjacent elements(except the string itself) to an ArrayList. However, I do not want to include elements from rows that exclude the specified string. If the

Java – splitting files by newline

How can I split file by newline? I’ve attempted to split by doing line.split(“\r?\n”) – but when I try printing the 0th index I get the entire file content when I was expecting just the first line. but if I try printing the result at index 0 I get the entire file content, when I expected to get just the

Advertisement