I want to return the smallest values from my words array Finding the shortest word is easy but I am not sure how to return a new array with the shortest words. The expected output is something like shorestWords [] = {“is”, “is”} Answer Since most of the answers are not considering that result is expected in String[] instead of
Tag: arrays
Iterating over arrays Check if an array contains two numbers
Write a program that reads an unsorted array of integers and two numbers n and m. The program must check if n and m occur next to each other in the array (in any order). Input data format The first line contains the size of an array. The second line contains elements of the array. The third line contains two
How to get odd or even lines from a two-dimensional array?
How to get odd or even lines from a two-dimensional array? And write them into 1 or 2 new arrays. Need to get: myData Array size unknown, maybe <5 , <6 Answer You can use math. You know that there will be half even and half odd. You can use that and a loop to copy the values from the
java.lang.ArrayStoreException on List to Array
When I use the toArray function from Java util I get an ArrayStoreException with no message. I implemented the absolute same code a year ago in pretty much the same Model and it works there, the query works fine and returns [1,2] from the DB. here is the code I use: I dont understand why it would not show an
Java OOP; creating array of objects
I’d like to create an array of objects where 3 objects are from one class, and a 4th is from second class. In the first class I did the following: in the second class I did the following: In the main class, I created several pupil objects and one tutor object, like this: Using objects for printing in main works
Deserialising JSON array using RestTemplate
I’m trying to convert JSON data to a java class using Rest Template. The JSON data has this format and cannot be changed: The java class to save the data is: To receive the JSON data and deserialize i’m doing: But i’m getting this exception: I’ve done this before and it worked, but the JSON data had a slightly different
Java Streams return throws error Unexpected return value
I am quite new to Java streams and I am trying to implement a method using the streams but when I try to return the value it’s throwing me the error Unexpected return value. I just wanted to know what am I doing wrong. Following is the return within the Arrays.stream value which is throwing the error: However, if I
How to get file name having particular content in it using java?
Here I am trying to read a folder containing .sql files and I am getting those files in an array, now my requirement is to read every file and find particular word like as join if join is present in the file return filename or else discard , someone can pls help me with this .. Answer You can search
Why do I have an error that my constructor is not visible even though my constructor is public [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. This question does not appear to be about programming within the scope defined in the help center. Closed 1 year ago. Improve this question I am working on a project to read a text from a note pad and store its content in a dynamic
Save a Resultset to an Array in java
I want to save the result of a whole Mysql table in an array it returns this to me from the database run: brandon Brandon Julio Daniel BUILD SUCCESSFUL (total time: 1 second) I want to save what is in the database in an array to be able to implement it with a sort and search method that’s why I