Is there a good way to check if the list is null when going around for loop in Java?
if (someList != null) {
for (Object object : someList) {
// // do whatever
}
}
//I
if (someList == null) {
return; // Or throw ex
}
for (Object object : someList) {
// // do whatever
}
Both of these look so dirty. Isn't there a cleaner way?
for-loop java loops syntax
for( Object o : safe( list ) ) {
// // do whatever
}
public static List safe( List other ) {
return other == null ? Collections.EMPTY_LIST : other;
}
You can do it this way.
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.