Bifalgorithm post · Computer science one · Comparisons
How can you create arrays and collections of strings in Java?
How can you create arrays and collections of strings in Java? (Computer science one · Comparisons) — "We can create our own arrays of strings similar to how we…
Ideas in this flowchart
- String collections can be created with arrays or dynamic collections.
- Arrays of strings work similarly to arrays of int and double values.
- An array of five strings is declared with String names[] = new String[5].
- The five array positions are assigned names such as Margaret Hamilton, Ada Lovelace, Grace Hopper, Marie Curie, and Hedy Lamarr.
- Dynamic collections such as List or Set can also store strings.
- A string list is declared with List<String> names = new ArrayList<String>().
- The names are inserted using repeated names.add(...) operations.
- The list contains the same five names as the array example.
- names.get(2) retrieves the element at index 2.
- The retrieval prints "Grace Hopper".