How to use string format with array of strings in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String[] arr1 = { "java", "c", "c++", "c#" };
        String[] arr2 = { "python", "php", "swift", "ruby" };

        for (int i = 0; i < arr1.length; i++) {
            String s = String.format("%1$-10s %2$10s", arr1[i], arr2[i]);
            
            System.out.println(s);
        }
    }
}




/*
run:

java           python
c                 php
c++             swift
c#               ruby

*/

 



answered Oct 9, 2020 by avibootz

Related questions

...