Ваш последний цикл выполняется бесконечно, потому что вы продолжаете добавлять элемент и проверять, есть ли у него предыдущий . Конечно, у него есть предыдущий, тот, который вы только что добавили.
Вы можете достичь желаемого с помощью: -
List<Integer> list = IntStream.range(0, 5)
.flatMap(i -> IntStream.of(56, i))
.boxed()
.collect(Collectors.toList());
System.out.println(list);
Вывод
[56, 0, 56, 1, 56, 2, 56, 3, 56, 4]
Существует несколько библиотек, доступных там. Выезд http://www.codeproject.com/KB/cs/PDFToText.aspx и http://itextsharp.sourceforge.net/
прилагают определенные усилия, но это возможно.
В огромных в большинстве случаев невозможно выполнить поиск содержимого PDF-файла напрямую, открыв его в блокноте - и даже в меньшинстве случаев (в зависимости от того, как был создан PDF-файл), вы сможете искать только отдельные слов из-за того, как PDF обрабатывает текст внутри.
У моей компании есть коммерческое решение, позволяющее извлекать текст из файла PDF. Ниже я включил для вас пример кода , как показано на этой странице , который демонстрирует, как искать в тексте файла PDF определенную строку.
using System;
using System.IO;
using QuickPDFDLL0718;
namespace QPLConsoleApp
{
public class QPL
{
public static void Main()
{
// This example uses the DLL edition of Quick PDF Library
// Create an instance of the class and give it the path to the DLL
PDFLibrary QP = new PDFLibrary("QuickPDFDLL0718.dll");
// Check if the DLL was loaded successfully
if (QP.LibraryLoaded())
{
// Insert license key here / Check the license key
if (QP.UnlockKey("...") == 1)
{
QP.LoadFromFile(@"C:\Program Files\Quick PDF Library\DLL\GettingStarted.pdf");
int iPageCount = QP.PageCount();
int PageNumber = 1;
int MatchesFound = 0;
while (PageNumber <= iPageCount)
{
QP.SelectPage(PageNumber);
string PageText = QP.GetPageText(3);
using (StreamWriter TempFile = new StreamWriter(QP.GetTempPath() + "temp" + PageNumber + ".txt"))
{
TempFile.Write(PageText);
}
string[] lines = File.ReadAllLines(QP.GetTempPath() + "temp" + PageNumber + ".txt");
string[][] grid = new string[lines.Length][];
for (int i = 0; i < lines.Length; i++)
{
grid[i] = lines[i].Split(',');
}
foreach (string[] line in grid)
{
string FindMatch = line[11];
// Update this string to the word that you're searching for.
// It can be one or more words (i.e. "sunday" or "last sunday".
if (FindMatch.Contains("characters"))
{
Console.WriteLine("Success! Word match found on page: " + PageNumber);
MatchesFound++;
}
}
PageNumber++;
}
if (MatchesFound == 0)
{
Console.WriteLine("Sorry! No matches found.");
}
else
{
Console.WriteLine();
Console.WriteLine("Total: " + MatchesFound + " matches found!");
}
Console.ReadLine();
}
}
}
}
}