Given a string array. Write a code to sort the strings in the array based on their 2nd character. Assumption :- Each array element contains more than one character. Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public class SortString { public static void main (String[] args) { String[] arr = { "heist" , "code" , "blog" , "python" , "java" }; for ( int i= 0 ; i<arr. length - 1 ; i++){ for ( int j=i+ 1 ; j<arr. length ; j++){ if (arr[i]. charAt ( 1 )>arr[j]. charAt ( 1 )){ String temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } for (String s:arr) System. out . println (s); } } Python (using sort and lambda) arr = [ "heist" , "code" , "blog" , "python" ,
This blog contains coding/programming and interview questions of MNCs like TCS, Wipro, Infosys, Capgemini, Mindtree, Amazon, Google, Facebook, Flipkart, Cisco, HP, Dell, etc. with placement preparation guides.