I just want to know how to print out Strings in an ArrayList with a given certain value only for the output. For example: I input “Hot”, “Cold”, “Pressure”, “Pain”. What method/control statement should I use to make so that the output will only be the words with four letters?
Output:
“Cold”
“Pain”
It only prints “Cold” & “Pain” because they’re the only one with four elements.
Will the use of .set be useful?
As explained in the comments, you could iterate over the list. If this is a repeated operation, you could use a map to sort the strings by length. See below an example with the 2 solutions: