当前位置: 首页>>代码示例>>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;未经允许,请勿转载。