當前位置: 首頁>>代碼示例>>Java>>正文


Java LinkedList.addFirst方法代碼示例

本文整理匯總了Java中java.util.LinkedList.addFirst方法的典型用法代碼示例。如果您正苦於以下問題:Java LinkedList.addFirst方法的具體用法?Java LinkedList.addFirst怎麽用?Java LinkedList.addFirst使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.LinkedList的用法示例。


在下文中一共展示了LinkedList.addFirst方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.util.LinkedList; //導入方法依賴的package包/類
public static void main(String[] args)
{
   String[] colors = {"black", "blue", "yellow"};
   LinkedList<String> links = new LinkedList<>(Arrays.asList(colors));

   links.addLast("red"); // add as last item
   links.add("pink"); // add to the end
   links.add(3, "green"); // add at 3rd index
   links.addFirst("cyan"); // add as first item      

   // get LinkedList elements as an array     
   colors = links.toArray(new String[links.size()]);

   System.out.println("colors: ");

   for (String color : colors)
      System.out.println(color);
}
 
開發者ID:cleitonferreira,項目名稱:LivroJavaComoProgramar10Edicao,代碼行數:19,代碼來源:UsingToArray.java

示例2: runGW2

import java.util.LinkedList; //導入方法依賴的package包/類
@SuppressWarnings("unused")
   //Create process Gw2-64.exe with some arguments
public void runGW2(){
       try {
       	if(cf.arg_string.getText().contains("Example")) cf.arg_string.setText("");
           cf.dispose();
           List<String> list= Arrays.asList(cf.arg_string.getText().split("\\s*,\\s*"));
           LinkedList<String> exe= new LinkedList<>(list);
           System.out.println(list);
           exe.addFirst(path+"\\Gw2-64.exe");
           Process process = new ProcessBuilder(exe).start();
           System.exit(0);
       } catch (IOException e1) {
           e1.printStackTrace();
           System.exit(1);
       }

   }
 
開發者ID:LithiumSR,項目名稱:gw2_launcher,代碼行數:19,代碼來源:MyActionListener.java

示例3: cloneUnLockedSubTree

import java.util.LinkedList; //導入方法依賴的package包/類
public LockTree cloneUnLockedSubTree() {

		LinkedList<LockTree> parents = new LinkedList<LockTree>();
		for (LockTree currentParent = parent; currentParent != null; currentParent = currentParent.parent) {
			parents.addFirst(currentParent);
		}
		LockTree oldPClone = null;
		for (LockTree p : parents) {

			LockTree pClone = new LockTree(name, oldPClone, p.clusterHead);

			if (oldPClone != null) {
				LinkedList<LockTree> pChild = new LinkedList<LockTree>();
				pChild.add(pClone);
				oldPClone.setChildren(pChild);
			}

			oldPClone = pClone;
		}

		LockTree clone = new LockTree(name, oldPClone, clusterHead);
		cloneChildren(this, clone);

		return clone;
	}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:26,代碼來源:LockTree.java

示例4: reduce

import java.util.LinkedList; //導入方法依賴的package包/類
private static Token reduce(Stack<Token> st, JobConf job) throws IOException {
  LinkedList<Token> args = new LinkedList<Token>();
  while (!st.isEmpty() && !TType.LPAREN.equals(st.peek().getType())) {
    args.addFirst(st.pop());
  }
  if (st.isEmpty()) {
    throw new IOException("Unmatched ')'");
  }
  st.pop();
  if (st.isEmpty() || !TType.IDENT.equals(st.peek().getType())) {
    throw new IOException("Identifier expected");
  }
  Node n = Node.forIdent(st.pop().getStr());
  n.parse(args, job);
  return new NodeToken(n);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:Parser.java

示例5: simulateJaveleonReload

import java.util.LinkedList; //導入方法依賴的package包/類
/** Only for use from Javeleon code. */
public List<Module> simulateJaveleonReload(Module moduleToReload) throws IllegalArgumentException {
    Set<Module> transitiveDependents = new HashSet<Module>(20);
    addToJaveleonDisableList(transitiveDependents, moduleToReload);
    Map<Module,List<Module>> deps = Util.moduleDependencies(transitiveDependents, modulesByName, getProvidersOf());
    try {
        LinkedList<Module> orderedForEnabling = new LinkedList<Module>();
        for (Module m : Utilities.topologicalSort(transitiveDependents, deps)) {
            if (m != moduleToReload) {
                orderedForEnabling.addFirst(m);
            }
        }
        return orderedForEnabling;
    } catch (TopologicalSortException ex) {
        return new ArrayList<Module>(transitiveDependents);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:ModuleManager.java

示例6: insertHighlightedLearner

import java.util.LinkedList; //導入方法依賴的package包/類
/**
    * Puts the searched learner in front of other learners in the list.
    */
   private static List<User> insertHighlightedLearner(User searchedLearner, List<User> latestLearners, int limit) {
latestLearners.remove(searchedLearner);
LinkedList<User> updatedLatestLearners = new LinkedList<User>(latestLearners);
updatedLatestLearners.addFirst(searchedLearner);
if (updatedLatestLearners.size() > limit) {
    updatedLatestLearners.removeLast();
}
return updatedLatestLearners;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:13,代碼來源:MonitoringAction.java

示例7: constructPath2

import java.util.LinkedList; //導入方法依賴的package包/類
public List<AbstractNodeLoc> constructPath2(AbstractNode<GeoNodeLoc> node)
{
	final LinkedList<AbstractNodeLoc> path = new LinkedList<>();
	int previousDirectionX = -1000;
	int previousDirectionY = -1000;
	int directionX;
	int directionY;
	
	while (node.getParent() != null)
	{
		// only add a new route point if moving direction changes
		directionX = node.getLoc().getNodeX() - node.getParent().getLoc().getNodeX();
		directionY = node.getLoc().getNodeY() - node.getParent().getLoc().getNodeY();
		
		if ((directionX != previousDirectionX) || (directionY != previousDirectionY))
		{
			previousDirectionX = directionX;
			previousDirectionY = directionY;
			path.addFirst(node.getLoc());
		}
		node = node.getParent();
	}
	return path;
}
 
開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:25,代碼來源:GeoPathFinding.java

示例8: onLoadFinished

import java.util.LinkedList; //導入方法依賴的package包/類
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    contactsAdapter.clear();

    Set<String> favoriteContacts = CustodeUtils.getFavoriteContacts(this);
    LinkedList<ContactsAdapter.ContactItem> tempArray = new LinkedList<>();
    int favoriteLimit = 0; // usato per ordinare i contatti preferiti in cima alla lista

    int nameColumnIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
    int numberColumnIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);

    while (cursor.moveToNext()) {
        String name = cursor.getString(nameColumnIndex);
        String number = cursor.getString(numberColumnIndex);

        boolean favorite = favoriteContacts.remove(number);
        if (favorite)
            tempArray.add(favoriteLimit++, new ContactsAdapter.ContactItem(name, number, true));
        else
            tempArray.addLast(new ContactsAdapter.ContactItem(name, number, false));
    }

    if (favoriteContacts.size() > 0) // => favoriteContacts contiene numeri che non sono più presenti in rubrica
        for (String favoriteContact : favoriteContacts)
            tempArray.addFirst(new ContactsAdapter.ContactItem("", favoriteContact, true));

    contactsAdapter.addAll(tempArray);
}
 
開發者ID:gvinciguerra,項目名稱:custode,代碼行數:29,代碼來源:ContactsPickerActivity.java

示例9: insertIntoSortedList

import java.util.LinkedList; //導入方法依賴的package包/類
public static int insertIntoSortedList(LinkedList<MultiLinkedPoint> listMLPnts, MultiLinkedPoint mlp, boolean bCvtedValue, int nSortBy)	{
	// assume dCompValue is not Nan nor Inf.
	double dCompValue = mlp.getPoint(bCvtedValue).getDim(nSortBy);

	int nOriginalSize = listMLPnts.size();
	if (nOriginalSize == 0)	{
		listMLPnts.add(mlp);
		return 0;
	} else if (dCompValue < listMLPnts.get(0).getPoint(bCvtedValue).getDim(nSortBy))	{
		listMLPnts.addFirst(mlp);
		return 0;
	} else if (dCompValue >= listMLPnts.get(nOriginalSize - 1).getPoint(bCvtedValue).getDim(nSortBy))	{
		listMLPnts.add(mlp);
		return nOriginalSize;
	} else	{
		int idxLeft = 0, idx = (nOriginalSize - 1)/2, idxRight = nOriginalSize - 1;
		while (idx != idxLeft)	{
			if (dCompValue < listMLPnts.get(idx).getPoint(bCvtedValue).getDim(nSortBy))	{
				idxRight = idx;
				idx = (idxRight + idxLeft)/2;
			} else	{	// if (dCompValue >= listMLPnts.get(idx).mpnt.getDim(nSortBy))	{
				idxLeft = idx;
				idx = (idxRight + idxLeft)/2;
			}
		}
		listMLPnts.add(idxLeft + 1, mlp);
		return idxLeft + 1;
	}
}
 
開發者ID:woshiwpa,項目名稱:CoreMathImgProc,代碼行數:30,代碼來源:DataSeries.java

示例10: finishProfileTree

import java.util.LinkedList; //導入方法依賴的package包/類
private static void finishProfileTree (ObjectProfileNode node)
{
    final LinkedList queue = new LinkedList ();
    IObjectProfileNode lastFinished = null;

    while (node != null)
    {
        // note that an unfinished non-shell node has its child count
        // in m_size and m_children[0] is its shell node:
         
        if ((node.m_size == 1) || (lastFinished == node.m_children [1]))
        {
            node.finish ();
            lastFinished = node;
        }
        else
        {
            queue.addFirst (node);
            for (int i = 1; i < node.m_size; ++ i)
            {
                final IObjectProfileNode child = node.m_children [i];
                queue.addFirst (child);
            }
        }
        
        if (queue.isEmpty ())
            return;
        else              
            node = (ObjectProfileNode) queue.removeFirst ();
    }
}
 
開發者ID:Ufkoku,項目名稱:SizeBasedEnhancedLruCache,代碼行數:32,代碼來源:ObjectProfiler.java

示例11: call

import java.util.LinkedList; //導入方法依賴的package包/類
@Override
public Elements call(Element e, List<String> args) {
    Element tmp = e.previousElementSibling();
    LinkedList<Element> tempList = Lists.newLinkedList();
    while (tmp != null) {
        tempList.addFirst(tmp);
        tmp = tmp.previousElementSibling();
    }
    return new Elements(tempList);
}
 
開發者ID:virjar,項目名稱:sipsoup,代碼行數:11,代碼來源:PrecedingSiblingFunction.java

示例12: fillCategoryPath

import java.util.LinkedList; //導入方法依賴的package包/類
private void fillCategoryPath(LinkedList<CategoryPathNode> path, Long id) {
    Category c = categoryRepository.findOne(id);
    // CategoryPathNode pathNode = new CategoryPathNode(c.getLevel(), c.getOrderNumber(), c.getId(), c.getParentId());
    CategoryPathNode pathNode = new CategoryPathNode(c.getLevel(), c.getId());
    path.addFirst(pathNode);
    if(c.getLevel() >= 0 && c.getParentId() != null) {
        fillCategoryPath(path, c.getParentId());
    }
}
 
開發者ID:chaokunyang,項目名稱:amanda,代碼行數:10,代碼來源:CategoryServiceImpl.java

示例13: memberPath

import java.util.LinkedList; //導入方法依賴的package包/類
private String memberPath(Element member) {
  LinkedList<String> names = new LinkedList<>();
  for (Element e = member; e.getKind() != ElementKind.PACKAGE; e = e.getEnclosingElement()) {
    names.addFirst(e.getSimpleName().toString());
  }
  String path = Joiner.on('.').join(names);
  String suffix = member.getKind() == ElementKind.METHOD ? "()" : "";
  return path + suffix;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:Encodings.java

示例14: main

import java.util.LinkedList; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static void main(String[] args) 
{
	Dog ououDog = new Dog("歐歐", "雪娜瑞");
	Dog yayaDog = new Dog("亞亞", "拉布拉多");
	Dog feifeiDog = new Dog("菲菲", "拉布拉多");
	Dog meimeiDog = new Dog("美美", "雪娜瑞");

	LinkedList dogs = new LinkedList();
	dogs.add(ououDog);
	dogs.add(yayaDog);
	dogs.addLast(meimeiDog);
	dogs.addFirst(feifeiDog);

	Dog firstDog = (Dog) dogs.getFirst();
	LOGGER.info("第一條狗狗的信息是:{}", firstDog);

	Dog lastDog = (Dog) dogs.getLast();
	LOGGER.info("最後一條狗狗的信息是:{}", lastDog);

	dogs.removeFirst();
	dogs.removeLast();

	LOGGER.info("剩下的狗狗是:");
	for (Object element : dogs) 
	{
		LOGGER.info(element);
	}

}
 
開發者ID:JAVA201708,項目名稱:Homework,代碼行數:31,代碼來源:Collection01.java

示例15: getPath

import java.util.LinkedList; //導入方法依賴的package包/類
/**
 * Returns a <code>List</code> of the edges on the shortest path from
 * <code>source</code> to <code>target</code>, in order of their occurrence
 * on this path. If either vertex is not in the graph for which this
 * instance was created, throws <code>IllegalArgumentException</code>.
 * 
 * @param epsilon
 *            max path length
 */
public LinkedList<E> getPath(V source, V target, int epsilon) {

	if (!g.containsVertex(source))
		throw new IllegalArgumentException("Specified source vertex "
				+ source + " is not part of graph " + g);

	if (!g.containsVertex(target))
		throw new IllegalArgumentException("Specified target vertex "
				+ target + " is not part of graph " + g);

	LinkedList<E> path = new LinkedList<E>();

	// collect path data; must use internal method rather than
	// calling getIncomingEdge() because getIncomingEdge() may
	// wipe out results if results are not cached
	Set<V> targets = new HashSet<V>();
	targets.add(target);
	singleSourceShortestPath(source, targets, g.getVertexCount());
	Map<V, E> incomingEdges = ((SourcePathData) sourceMap.get(source)).incomingEdges;

	if (incomingEdges.isEmpty() || incomingEdges.get(target) == null) {
		return null;
	}

	V current = target;
	while (!current.equals(source)) {
		E incoming = incomingEdges.get(current);
		path.addFirst(incoming);
		current = ((Graph<V, E>) g).getOpposite(current, incoming);
	}

	if (epsilon != -1 && path.size() > epsilon) {
		return null;
	}

	Double d = getDistance(source, target).doubleValue();
	if (d == Double.POSITIVE_INFINITY) {
		return null;
	}
	return path;
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:51,代碼來源:MyDijkstraShortestPath.java


注:本文中的java.util.LinkedList.addFirst方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。