
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Can you help me fix my code in Java, please? I am stuck to keep going.
Thank you
![String Refinement
to
Fill in the refineStringArray method so that it returns an array of
all the Strings in the given array that have length greater or equal
the length of a given string. If the array is null or empty, or the given
string is null, return null. The output strings should be in the same
order they appear in the original array. Note that if the array contains
any null element, then you need to skip that null element.
Example 1
refineStringArray (new String[] {"Hello World", "a", "abc"}, "oop")
should return
{"Hello World", "abc"}
Example 2
refineStringArray (new String[] {"a", "ab", "abc"}, "java")
should return
{}
Example 3
refineStringArray (new String[] {"Hello World", "a", "abc"}, null)
should return
null
1 public class StringRefinement {
123456
7896
10
11
12
13
14
public static String[] refineStringArray (String[] strings, String toCompare) {
refineStringArray (new String[] {"Hello World", "a", "abc"}, null);
for (int i=0;i<strings.length; i++) {
if(string[i]==String toCompare) return 1;
return null;
}
}
public static void main(String[] args) {
refineStringArray();
}
/home/StringRefinement.java 14:2 Tabs (Auto)
Terminal
[user@sahara ~]$ java StringRefinement.java
StringRefinement.java:6: error: ')' expected
if(string[i]==String toCompare) return 1;
A
StringRefinement.java:6: error: not a statement
if(string[i]==String toCompare) return 1;
A
StringRefinement.java:6: error: ';' expected
if(string[i]==String toCompare) return 1;](https://content.bartleby.com/qna-images/question/ec2ae404-0619-4da1-b41d-2b12da835c13/d3138977-5d0d-4baa-979e-e2bf98d64287/wafekm_thumbnail.png)
Transcribed Image Text:String Refinement
to
Fill in the refineStringArray method so that it returns an array of
all the Strings in the given array that have length greater or equal
the length of a given string. If the array is null or empty, or the given
string is null, return null. The output strings should be in the same
order they appear in the original array. Note that if the array contains
any null element, then you need to skip that null element.
Example 1
refineStringArray (new String[] {"Hello World", "a", "abc"}, "oop")
should return
{"Hello World", "abc"}
Example 2
refineStringArray (new String[] {"a", "ab", "abc"}, "java")
should return
{}
Example 3
refineStringArray (new String[] {"Hello World", "a", "abc"}, null)
should return
null
1 public class StringRefinement {
123456
7896
10
11
12
13
14
public static String[] refineStringArray (String[] strings, String toCompare) {
refineStringArray (new String[] {"Hello World", "a", "abc"}, null);
for (int i=0;i<strings.length; i++) {
if(string[i]==String toCompare) return 1;
return null;
}
}
public static void main(String[] args) {
refineStringArray();
}
/home/StringRefinement.java 14:2 Tabs (Auto)
Terminal
[user@sahara ~]$ java StringRefinement.java
StringRefinement.java:6: error: ')' expected
if(string[i]==String toCompare) return 1;
A
StringRefinement.java:6: error: not a statement
if(string[i]==String toCompare) return 1;
A
StringRefinement.java:6: error: ';' expected
if(string[i]==String toCompare) return 1;
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- NOTE: Please do not copy from another person's answer, if you do so, you will be given down vote/thumb down. Thank you! Also, No entire code is needed. Just provide the method for LList class in Java ------------------------------------------------------------------------------------------------------------------------------------------------------- Suppose that a list contains Comparable objects. Implement a method that returns a new list of items that are less than some given item. The header of the method could be as follows: public LList<T> getAllLessThan( Comparable<T> anObject) Write an implementation of this method for the class LList. Make sure that your method does not affect the state of the original list.arrow_forwardPlease give a full detailed optimized solution in Java 8 for the given problem, use the example code provided as well. Please provide comments and screenshots of code and output. Also, add the time/space complexity and the reason for it.Java 8 Code Example:import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String args[] ) throws Exception { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ } }arrow_forwardThis is Java Programming! We are working with MaxHeap Instructions: Don't modify the two codes below. You need to make a MaxHeapInterface.java that implements the bstMaxHeap in the Driver.java code. If you haven't look at the code, look at them now. Driver.java code: /** A driver that demonstrates the class BstMaxHeap. @author Frank M. Carrano @author Timothy M. Henry @version 5.0*/public class Driver {public static void main(String[] args) { String jared = "Jared"; String brittany = "Brittany"; String brett = "Brett"; String doug = "Doug"; String megan = "Megan"; String jim = "Jim"; String whitney = "Whitney"; String matt = "Matt"; String regis = "Regis"; MaxHeapInterface<String> aHeap = new BstMaxHeap<>(); aHeap.add(jared); aHeap.add(brittany); aHeap.add(brett); aHeap.add(doug); aHeap.add(megan); aHeap.add(jim); aHeap.add(whitney); aHeap.add(matt); aHeap.add(regis); if (aHeap.isEmpty()) System.out.println("The heap is empty -…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education