reverse array in java
int length = array.length;
for(int i=0;i<length/2;i++) {
int swap = array[i];
array[i] = array[length-i-1];
array[length-i-1] = swap;
}
or
Collections.reverse(Arrays.asList(array));
reverse array in java
int length = array.length;
for(int i=0;i<length/2;i++) {
int swap = array[i];
array[i] = array[length-i-1];
array[length-i-1] = swap;
}
or
Collections.reverse(Arrays.asList(array));
how to reverse a list in java
List<String> stringList = Arrays.asList("A", "B", "C");
Collections.reverse(stringList);
assertThat(stringList).containsExactly("C", "B", "A");
how to reverse a string in java
public class ReverseString {
public static void main(String[] args) {
String s1 = "neelendra";
for(int i=s1.length()-1;i>=0;i--)
{
System.out.print(s1.charAt(i));
}
}
}
string reverse in java
String str = "Hello";
String reverse(String str){
StringBuilder sb = new StringBuilder();
sb.append(str);
sb.reverse();
return sb.toString();
}
reverse in jaav
// my linkedin : https://www.linkedin.com/in/vaalarivan-prasanna-3a07bb203/
list = new ArrayList<int> {3, 4, 7}; //initialising a list
Collections.reverse(list); //reverses a List or an ArrayList
//now, list is {7, 4, 3}
String reverse in java
1)
String str = "Hello";
String result = "";
for(int i = str.length()-1; i>=0; i--){
result += str.charAt(i); // first solution, charAt method
// result += str1.substring(i, i+1); // first solution, substring method
}
System.out.println(result);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us