String Array with Enhanced For Loop in Java Last Updated : 08 Apr, 2023 Comments Improve Suggest changes Like Article Like Report Enhanced for loop(for-each loop) was introduced in java version 1.5 and it is also a control flow statement that iterates a part of the program multiple times. This for-loop provides another way for traversing the array or collections and hence it is mainly used for traversing arrays or collections. This loop also makes the code more readable and reduces the chance of bugs in the code. Syntax: for(data-type variable : array | collection) { // Code to be executed } In this article, we will see how to get array Strings using Enhanced For Loop. Implementation Java /*package whatever //do not write package name here */ import java.io.*; class GFG { public static void main(String[] args) { String str[] = { "java", "kotlin", "c#", "c" }; // Using Enhanced For Loop for (String str1 : str) { System.out.println(str1); } } } Outputjava kotlin c# c Comment More infoAdvertise with us Next Article String Array with Enhanced For Loop in Java R rushikesh_here1 Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Convert a String to a List of Characters in Java In Java, to convert a string into a list of characters, we can use several methods depending on the requirements. In this article, we will learn how to convert a string to a list of characters in Java.Example:In this example, we will use the toCharArray() method to convert a String into a character 3 min read How to Convert Character Array to String in Java? Strings are defined as an array of characters. The difference between a character array and a string is the string is terminated with a special character "\0". A character array can be converted to a string and vice versa. In this article, we will discuss how to convert a character array to a string 4 min read Convert Set of String to Array of String in Java Given a Set of Strings, the task is to convert the Set into an Array of Strings in Java. Examples: Input: Set<String>: ["ForGeeks", "A Computer Portal", "Geeks"] Output: String[]: ["ForGeeks", "A Computer Portal", "Geeks"] Input: Set<String>: ["G", "e", "k", "s"] Output: String[]: ["G", 6 min read Java for loop vs Enhanced for loop In Java, loops are fundamental constructs for iterating over data structures or repeating blocks of code. Two commonly used loops are the for loop and the enhanced for loop. While they serve similar purposes, their applications and usage vary based on the scenario.for loop vs Enhanced for loopBelow 4 min read Convert List of Characters to String in Java Given a list of characters. In this article, we will write a Java program to convert the given list to a string. Example of List-to-String ConversionInput : list = {'g', 'e', 'e', 'k', 's'} Output : "geeks" Input : list = {'a', 'b', 'c'} Output : "abc" Strings - Strings in Java are objects that are 4 min read StringBuilder charAt() in Java with Examples The charAt(int index) method of StringBuilder Class is used to return the character at the specified index of String contained by StringBuilder Object. The index value should lie between 0 and length()-1. Syntax: public char charAt(int index) Parameters: This method accepts one int type parameter in 3 min read How to Optimize String Creation in Java? In Java, strings are frequently used, and optimizing their creation can help improve performance, especially when creating many strings in a program. In this article, we will explore simple ways to optimize string creation in Java.Example:Using the new keyword creates a new string object. This is st 2 min read For-Each Loop in Java The for-each loop in Java (also called the enhanced for loop) was introduced in Java 5 to simplify iteration over arrays and collections. It is cleaner and more readable than the traditional for loop and is commonly used when the exact index of an element is not required.Example: Using a for-each lo 8 min read String Arrays in Java A String Array in Java is an array that stores string values. The string is nothing but an object representing a sequence of char values. Strings are immutable in Java, this means their values cannot be modified once created.When we create an array of type String in Java, it is called a String Array 5 min read Java String Class indent() Method With Examples JDK 12 introduced indent() method in Java.lang.String class. This method is useful to add or remove white spaces from the beginning of the line to adjust indentation for each string line. Syntax: public String indent(int n) Parameter: It takes integer n as input and does indentation accordingly. Al 3 min read Like