Skip to content

Instantly share code, notes, and snippets.

@johnludwigm
Last active February 4, 2018 17:11
Show Gist options
  • Save johnludwigm/7d4d457e81c6894f26bc77911ba7eb94 to your computer and use it in GitHub Desktop.
Save johnludwigm/7d4d457e81c6894f26bc77911ba7eb94 to your computer and use it in GitHub Desktop.
Example of in-line assignment
import java.io.*;
class Main {
public static void main(String[] args) {
String fileName = "blog.txt";
FileReader fileReader = new FileReader(fileName);
BufferedReader br = new BufferedReader(fileReader);
String line;
//Observe that line is assigned to br.readLine within this line of code
//while another process (comparing to null) is happening.
while ((line = br.readLine()) != null) {
//process the line, or do whatever.
}
br.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment