What is an anonymous array? Give example
Answers
➡️
- What is an anonymous array? Give example
Anonymous arrays :
In addition to the above specified ways you can create an array without specifying any name such arrays are known as anonymous arrays. Since it doesn’t have name to refer you can use it only once in your program. Generally, anonymous arrays are passed as arguments to methods.
You can create an anonymous array by initializing it at the time of creation.
EXAMPLE
In the following Java program the arrayToUpperCase() method accepts an array of Strings, converts each String to upper case and prints the results.
To this method we are passing an anonymous array of Strngs as a parameter.
public class AnonymousArray {
public static void arrayToUpperCase(String [] array) {
for(int i=0; i< array.length; i++) {
char[] ch = array[i].toCharArray();
for(int j=0; j<ch.length; j++){
ch[j] = Character.toUpperCase(ch[j]);
}
System.out.println(new String(ch));
}
}
public static void main(String args[]) {
arrayToUpperCase(new String[] {"Krishna", "Vishnu", "Dhana", "Rupa", "Raja", "Kavya"});
}
}
Output
KRISHNA
VISHNU
DHANA
RUPA
RAJA
KAVYA
ig:silent___readers
Answer:
Array :- Batch, bundle, cluster, design, pattern...etc..