Here you can find the source of readLines(String lines)
Parameter | Description |
---|---|
lines | A String containing the lines to be separated. |
public static LinkedList<String> readLines(String lines) throws IOException
//package com.java2s; /* Utilities used to manipulate strings. Copyright (c) 2002-2013 The Regents of the University of California. All rights reserved./*from w w w. j a v a 2 s .com*/ Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. PT_COPYRIGHT_VERSION_2 COPYRIGHTENDKEY */ import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; import java.util.LinkedList; public class Main { /** Return a LinkedList of the lines in a string that aren't comments. * @param lines A String containing the lines to be separated. * @return A LinkedList of the lines that aren't comments. * @exception IOException If thrown when reading from the input String. */ public static LinkedList<String> readLines(String lines) throws IOException { BufferedReader bufferedReader = null; LinkedList<String> returnList = new LinkedList<String>(); String line; bufferedReader = new BufferedReader(new StringReader(lines)); try { // Read line by line, skipping comments. while ((line = bufferedReader.readLine()) != null) { line = line.trim(); if (!(line.length() == 0 || line.startsWith("/*") || line .startsWith("//"))) { returnList.add(line); } } } finally { if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException ex) { // Ignore ex.printStackTrace(); } } } return returnList; } }