Added function to print a list

This commit is contained in:
2021-06-30 16:52:31 -04:00
parent cebe376c1b
commit 8b8309199d
2 changed files with 41 additions and 0 deletions

View File

@@ -968,4 +968,16 @@ public class Algorithms{
//Conver the number to binary string
return num.toString(2);
}
//Print a list
public static <T> String printList(ArrayList<T> list){
StringBuilder listString = new StringBuilder("[");
for(int cnt = 0;cnt < list.size();++cnt){
listString.append(list.get(cnt));
if(cnt < list.size() - 1){
listString.append(", ");
}
}
listString.append("]");
return listString.toString();
}
}