Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA PLEASE! Write a method called listlength() that takes in a list of strings and returns a list of their lengths as integers. You

IN JAVA PLEASE!

image text in transcribed

Write a method called listlength() that takes in a list of strings and returns a list of their lengths as integers. You must create a new list for your answer. Hint: Please use java built-in ArrayList and List to complete the method. Examples: listLength(list("", "", "ab", "abc")) -> list(e, 1, 2, 3) listLength(list("hello world")) -> list(11) listLength(list()) -> list() Note: In the Java built-in List class, the following methods may be useful for you in the question: - Eget(int index): Returns the element at the specified position in this list. For example, in String Araaylist("", "a", "b", "abc" }, the return of its get(1) method would be "a" - void add(e e): Appends the specified element to the end of this list (optional operation). For example, ArrayList list - new ArrayList(); list.add(""); In Java built-in String class, the length() method can be used to retrieve the length of a string. For example, String name = "hello world"; name.length() will return 11. //--- public class Questioni ( public List listLength(List list) { //make a new ArrayList, named lengthList //TODO2 for each element in the given list do by list.get(index) or enriched for loop calculate element text string length by String's length() method // insert the calculated length 1/TODO3 return lengthList } public static void main(String[] args) { ArrayList list = new ArrayList(); list.add(""); //insert a empty string list.add("a"); //append "a" list.add("ab"); //append "ab" list.add("abc"); //append "abc System.out.println(list.get(3));//display "abc" Questioni a - new Question(); q.listLength(list); } need to copy and paste the whole program for submission. But

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

1. How do cultures and social communities shape communication?

Answered: 1 week ago