10 changed files with 121 additions and 0 deletions
@ -0,0 +1,4 @@ |
|||||
|
package PACKAGE_NAME; |
||||
|
|
||||
|
public class Pair { |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
### IntelliJ IDEA ### |
||||
|
out/ |
||||
|
!**/src/main/**/out/ |
||||
|
!**/src/test/**/out/ |
||||
|
.kotlin |
||||
|
|
||||
|
### Eclipse ### |
||||
|
.apt_generated |
||||
|
.classpath |
||||
|
.factorypath |
||||
|
.project |
||||
|
.settings |
||||
|
.springBeans |
||||
|
.sts4-cache |
||||
|
bin/ |
||||
|
!**/src/main/**/bin/ |
||||
|
!**/src/test/**/bin/ |
||||
|
|
||||
|
### NetBeans ### |
||||
|
/nbproject/private/ |
||||
|
/nbbuild/ |
||||
|
/dist/ |
||||
|
/nbdist/ |
||||
|
/.nb-gradle/ |
||||
|
|
||||
|
### VS Code ### |
||||
|
.vscode/ |
||||
|
|
||||
|
### Mac OS ### |
||||
|
.DS_Store |
||||
@ -0,0 +1,10 @@ |
|||||
|
# 默认忽略的文件 |
||||
|
/shelf/ |
||||
|
/workspace.xml |
||||
|
# 已忽略包含查询文件的默认文件夹 |
||||
|
/queries/ |
||||
|
# Datasource local storage ignored files |
||||
|
/dataSources/ |
||||
|
/dataSources.local.xml |
||||
|
# 基于编辑器的 HTTP 客户端请求 |
||||
|
/httpRequests/ |
||||
@ -0,0 +1,6 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project version="4"> |
||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK"> |
||||
|
<output url="file://$PROJECT_DIR$/out" /> |
||||
|
</component> |
||||
|
</project> |
||||
@ -0,0 +1,8 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project version="4"> |
||||
|
<component name="ProjectModuleManager"> |
||||
|
<modules> |
||||
|
<module fileurl="file://$PROJECT_DIR$/w8.iml" filepath="$PROJECT_DIR$/w8.iml" /> |
||||
|
</modules> |
||||
|
</component> |
||||
|
</project> |
||||
@ -0,0 +1,6 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project version="4"> |
||||
|
<component name="VcsDirectoryMappings"> |
||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" /> |
||||
|
</component> |
||||
|
</project> |
||||
@ -0,0 +1,31 @@ |
|||||
|
package com.example; |
||||
|
|
||||
|
|
||||
|
|
||||
|
public class Pair<K,V> { |
||||
|
private K key; |
||||
|
private V value; |
||||
|
public Pair(K key,V value){ |
||||
|
this.key = key; |
||||
|
this.value = value; |
||||
|
} |
||||
|
public K getKey(){ |
||||
|
return key; |
||||
|
} |
||||
|
public void setKey(K key){ |
||||
|
this.key = key; |
||||
|
} |
||||
|
public V getValue(){ |
||||
|
return value; |
||||
|
} |
||||
|
public void setValue(V value){ |
||||
|
this.value =value; |
||||
|
} |
||||
|
@Override |
||||
|
public String toString(){ |
||||
|
return "Pair{"+"key="+key+",value="+value+"}"; |
||||
|
} |
||||
|
public static <K,V>Pair<V,K>swap(Pair<K,V>pair){ |
||||
|
return new Pair<>(pair.getValue(), pair.getKey()); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
package com.example; |
||||
|
|
||||
|
public class PairTest { |
||||
|
public static void main(String[] args){ |
||||
|
Pair<String,Integer>pair1 = new Pair<>("年龄",20); |
||||
|
System.out.println("交换前:" + pair1); |
||||
|
Pair<Integer,String>swapped1 = Pair.swap(pair1); |
||||
|
System.out.println("交换后:"+swapped1); |
||||
|
System.out.println("---------------------"); |
||||
|
Pair<Integer,String>pair2 = new Pair<>(1001,"张三"); |
||||
|
System.out.println("交换前:" + pair2); |
||||
|
Pair<String,Integer>swapped2 = Pair.swap(pair2); |
||||
|
System.out.println("交换后:" +swapped2); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<module type="JAVA_MODULE" version="4"> |
||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true"> |
||||
|
<exclude-output /> |
||||
|
<content url="file://$MODULE_DIR$"> |
||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> |
||||
|
</content> |
||||
|
<orderEntry type="inheritedJdk" /> |
||||
|
<orderEntry type="sourceFolder" forTests="false" /> |
||||
|
</component> |
||||
|
</module> |
||||
|
After Width: | Height: | Size: 217 KiB |
Loading…
Reference in new issue